1. 刚开始的波形不太对,比如如下代码
i2c_status = I2C_write( at24c02_write_buf, //pointer to data array
, //length of data to be transmitted
, //master or slaver
0x78, //slave address to transmit to
, //transfer mode of operation
//time out for bus busy
);
但是实际的波形是,把0x78左移了一位,我估计是DSP5509会自动在最后一位加上读写位
所以本次AT24C02的地址是0XA0,那么实际写的应该是0x50
i2c_status = I2C_write( at24c02_write_buf, //pointer to data array
, //length of data to be transmitted
, //master or slaver
0x50, //slave address to transmit to
, //transfer mode of operation
//time out for bus busy
);
2. 最后的综合代码如下
#include <csl.h>
#include <csl_i2c.h>
#include <stdio.h>
#include <csl_pll.h>
#include <csl_gpio.h> #define BUF_LEN 20
#define AT24C02_WRITE_ADDR 0x50
#define AT24C02_READ_ADDR 0X50 Uint16 i2c_status; /*锁相环的设置*/
PLL_Config myConfig = {
, //IAI: the PLL locks using the same process that was underway
//before the idle mode was entered
, //IOB: If the PLL indicates a break in the phase lock,
//it switches to its bypass mode and restarts the PLL phase-locking
//sequence
, //PLL multiply value; multiply 24 times
//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)
}; /* This next struct shows how to use the I2C API */
/* Create and initialize an I2C initialization structure */
I2C_Setup I2Cinit = {
, /* 7 bit address mode */
, /* own address - don't care if master */
, /* clkout value (Mhz) */
, /* a number between 10 and 400*/
, /* number of bits/byte to be received or transmitted (8)*/
, /* DLB mode on*/
/* FREE mode of operation on*/
}; Uint16 at24c02_write_buf[] ={0x00,0x00,0x00};
Uint16 test_write_buf[BUF_LEN+] = {};
I2C_Config testI2C; void delay(Uint32 k)
{
while(k--);
} void main(void)
{
unsigned char i= ;
i2c_status = ;
/*初始化CSL库*/
CSL_init(); /*设置系统的运行速度为140MHz*/
PLL_config(&myConfig); /*确定方向为输出*/
GPIO_RSET(IODIR,0xFF);
GPIO_RSET(IODATA,0x00); /*I2C is undet reset*/
I2C_RSET(I2CMDR,);
/*设置预分频寄存器,I2C的mode clock is 10MHz*/
delay();
I2C_RSET(I2CSAR,0x001A);
I2C_RSET(I2CMDR,0x0620); I2C_setup(&I2Cinit);
/*设置I2C的Mater clock*/
I2C_RSET(I2CCLKL,);
I2C_RSET(I2CCLKH,); I2C_getConfig(&testI2C); //
for(i=;i<BUF_LEN;i++)
{
at24c02_write_buf[] = i;
at24c02_write_buf[] = +i;
i2c_status = I2C_write( at24c02_write_buf, //pointer to data array
, //length of data to be transmitted
, //master or slaver
AT24C02_WRITE_ADDR, //slave address to transmit to
, //transfer mode of operation
//time out for bus busy
);
delay();
} for(i=;i<BUF_LEN;i++)
{
at24c02_write_buf[] = i;
at24c02_write_buf[] = ;
test_write_buf[i] = ;
i2c_status = I2C_write( at24c02_write_buf, //pointer to data array
, //length of data to be transmitted
, //master or slaver
AT24C02_WRITE_ADDR, //slave address to transmit to
, //transfer mode of operation
//time out for bus busy
); i2c_status = I2C_read( &(test_write_buf[i]), //pointer to data array
, //length of data to be transmitted
, //master or slaver
AT24C02_READ_ADDR, //slave address to transmit to
, //transfer mode of operation
, //time out for bus busy );
delay();
} while();
}
3. 看下仿真的结果
4. 看下写数据的波形
读数据的波形