//void I2C_24C512_Write(u8 RegName, u16 RegValue) void I2C_24CXX_Write(u16 nAddr, u8* pDat, u16 nLen) { u16 i = 0; /* Enable I2C1 acknowledgement if it is already disabled by other function */ I2C_AcknowledgeConfig(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) /* EV5 */ { }
/* Send slave address for write */ I2C_Send7bitAddress(I2C1, ADDR_24CXX, I2C_Direction_Transmitter);
/* Test on I2C1 EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */ { }
/* Send the high part of memory address */ /* I2C_SendData(I2C1, (u8)(nAddr>>8));
// Test on I2C1 EV8 and clear it while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) // EV8 { } */
/* Send the low part of memory address */ I2C_SendData(I2C1, (u8)nAddr);
/* Test on I2C1 EV8 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */ { }
for(i=0;i<nLen;i++) { /* Send I2C1 data */ I2C_SendData(I2C1, pDat);
/* Test on I2C1 EV8 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */ { } } /* Send I2C1 STOP Condition */ I2C_GenerateSTOP(I2C1, ENABLE); }
void I2C_24CXX_Read(u16 nAddr, u8* pDat, u16 nLen) { u16 i = 0; /* Enable I2C1 acknowledgement if it is already disabled by other function */ I2C_AcknowledgeConfig(I2C1, ENABLE);
/* Test on I2C1 EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */ { }
/* // Send the high part of memory address I2C_SendData(I2C1, (u8)(nAddr>>8));
// Test on I2C1 EV8 and clear it while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) // EV8 { } */ /* Send the low part of memory address */ I2C_SendData(I2C1, (u8)nAddr);
/* Test on I2C1 EV8 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */ { }