用南京万利电子的EK-STM32F开发板上调试程序,使用I2C1读写外部24C02芯片遇到在写PAGE时,发完开始条件后,一直在等待EV5,我用的是FWLIB里的I2C EXSAMPLE5例程,I2C 作如下修改以适应万利EK-STM32F开发板,这个问题论坛上有不少人提到,希望万利和ST写出可以在开发板上使用的例程。 i2c_ee.h #define EEPROM_Block0_ADDRESS 0xA0 /* E2 = 0 */
i2c_ee.c #define I2C_Speed 400000 #define I2C1_SLAVE_ADDRESS7 0xA0 #define I2C_PageSize 4
void I2C_EE_PageWrite(u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite) { /* Send START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); /* Send EEPROM address for write */ I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Send the EEPROM's internal address to write to */ I2C_SendData(I2C1, WriteAddr);
/* Test on EV8 and clear it */ while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* While there is data to be written */ while(NumByteToWrite--) { /* Send the current byte */ I2C_SendData(I2C1, *pBuffer);
/* Point to the next byte to be written */ pBuffer++; /* Test on EV8 and clear it */ while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); }
/* Send STOP condition */ I2C_GenerateSTOP(I2C1, ENABLE); } |