从调试结果看,读到的是当前地址的数据,而不是写入地址的数据,读函数如下uint8_t Read_24LC64(uint32_t address)
{
uint8_t TEMP;
//Open I2C1 and set clock = 50Kbps
SystemCoreClock = DrvSYS_GetHCLKFreq();
DrvI2C_Open(I2C_PORT1, 50000);
//send i2c start
DrvI2C_Ctrl(I2C_PORT1, 1, 0, 1, 0); //set start
while (I2C1->I2CON.SI == 0); //poll si flag
//send writer command
I2C1->I2CDAT = 0XA0;
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0); //clr si
while( I2C1->I2CON.SI == 0 ); //poll si flag
//send address high
I2C1->I2CDAT = (address>>8)&0XFF;
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 1); //clr si and set ack
while( I2C1->I2CON.SI == 0 ); //poll si flag
//send address low
I2C1->I2CDAT = address&0XFF;
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0); //clr si and set ack
while( I2C1->I2CON.SI == 0 ); //poll si flag
//send start flag
DrvI2C_Ctrl(I2C_PORT1, 1, 0, 1, 0); //clr si and send start
while( I2C1->I2CON.SI == 0 ); //poll si flag
//send read command
I2C1->I2CDAT = 0XA1;
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 1); //clr si
while( I2C1->I2CON.SI == 0 ); //poll si flag
//resive data
I2C1->I2CDAT = 0XFF;
DrvI2C_Ctrl(I2C_PORT1, 0, 0, 1, 0); //clr si
while( I2C1->I2CON.SI == 0 ); //poll si flag
TEMP= I2C1->I2CDAT;
//send i2c stop
DrvI2C_Ctrl(I2C_PORT1, 0, 1, 1, 0); //clr si and set stop
while( I2C1->I2CON.STO);
DrvI2C_Close(I2C_PORT1);
return TEMP;
}
|