⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main_i2c2.c

📁 DSPC5509的i2C程序
💻 C
字号:
/*
 * Copyright (C) 2003 Texas Instruments Incorporated
 * All Rights Reserved
 */
/*
 *---------main_i2c2.c---------
 * This example shows how to use the I2C API to transfer a byte of 
 * data in loopback mode.                                    
 */
 
#include <csl_i2c.h>
#include <stdio.h>
#include <csl_pll.h>


#define OV_WRITE_ADDR 0x60
#define OV_READ_ADDR 0x61

//---------Global data definition---------
int x=0,y,z;
Uint16 data_send[2]={0x09,0x01};
Uint16 datareceive[1]={0};
Uint16 PID[1]={0x0A};         //0x96
Uint16 VER[1]={0x0B};         //0x52
/*锁相环的设置*/
PLL_Config  myConfig      = {
  0,    //IAI: the PLL locks using the same process that was underway 
                //before the idle mode was entered
  1,    //IOB: If the PLL indicates a break in the phase lock, 
                //it switches to its bypass mode and restarts the PLL phase-locking 
                //sequence
  12,    //PLL multiply value; multiply 24 times
  0             //Divide by 2 PLL divide value; it can be either PLL divide value 
                //(when PLL is enabled), or Bypass-mode divide value
                //(PLL in bypass mode, if PLL multiply value is set to 1)
};

/* Create and initialize an I2C initialization structure */
I2C_Setup I2Cinit = {
        0,              /* 7 bit address mode */
        0x0020,         /* own address - don't care if master */
        144,            /* clkout value (Mhz)  */
        100,            /* a number between 10 and 400*/
        0,              /* number of bits/byte to be received or transmitted (8)*/
        0,              /* DLB mode off*/
        0               /* FREE mode of operation on*/
};


//---------Function prototypes---------
void taskFunc(void);

//---------main routine---------
void main(void)
{
    /* Initialize CSL library - This is REQUIRED !!! */
    CSL_init();
	/*设置系统的运行速度为144MHz*/
    PLL_config(&myConfig);
 
    /* Call I2C example task/func */
    taskFunc();
}

void taskFunc(void) {
 
    int err = 1;
    /* Initialize I2C, using parameters in init structure */
    I2C_setup(&I2Cinit); 

	/*I2C is undet reset*/
//	I2C_RSET(I2CMDR,0);
	/*设置预分频寄存器,I2C的mode clock is 12MHz*/
//	I2C_RSET(I2CPSC,0xb);
//	I2C_RSET(I2CMDR,0x4620);	
	
//  I2C_setup(&I2Cinit);
  	/*设置I2C的Mater clock*/
//	I2C_RSET(I2CCLKL,5);
//	I2C_RSET(I2CCLKH,5);


    /* Write a data byte to I2C */
//      x=I2C_write(databyte1,1,1,0x60,1,30000);
      x=I2C_write(PID,1,1,OV_WRITE_ADDR,1,30000);
       if(!x) printf ("\n x PASSED\n");
       else printf ("\n x FAILED\n");
      z=I2C_read(datareceive,1,1,OV_READ_ADDR,1,30000,0);
       if(!z) printf ("\n z PASSED\n");
       else printf ("\n z FAILED\n");
    /* Read data byte from I2C */
/*
    I2C_read( data_write,//pointer to data array
	    	   2,				//length of data to be transmitted
	    	   1,				//master or slaver
	    	   OV_READ_ADDR,	    //slave address to transmit to
	    	   1,				//transfer mode of operation
	    	   30000			//time out for bus busy
	    		);            
*/
//    z=I2C_read(datareceive1,1,1,0x61,0,30000,0);
//      if(!z) printf ("\nTEST PASSED\n");
//      else printf ("\nTEST FAILED\n");
    /* Make sure the received byte is same as one sent */
 //   if (databyte1[0]==datareceive1[0]) {
//       err = 0;
//    }
//    printf ("%s\n",err?"TEST FAILED" : "TEST PASSED");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -