请教大侠们一个I2C的问题,I2C何时产生SCL呢??当I2c写的时候知道是 数据写到DR时 就产生的SCL时钟,但是 当I2C读的时候,就是下面的时候:
void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead)
{
/* While the bus is busy */
while(I2C_GetFlagStatus(I2C_EE, I2C_FLAG_BUSY));
/* Send START condition */
I2C_GenerateSTART(I2C_EE, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for write */
I2C_Send7bitAddress(I2C_EE, EEPROM_ADDRESS, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
#ifdef EE_M24C08
/* Send the EEPROM's internal address to read from: Only one byte address */
I2C_SendData(I2C_EE, ReadAddr);
#elif defined (EE_M24C64_32)
/* Send the EEPROM's internal address to read from: MSB of the address first */
I2C_SendData(I2C_EE, (uint8_t)((ReadAddr & 0xFF00) >> 8));
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send the EEPROM's internal address to read from: LSB of the address */
I2C_SendData(I2C_EE, (uint8_t)(ReadAddr & 0x00FF));
#endif /* EE_M24C08 */
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(I2C_EE, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for read */
I2C_Send7bitAddress(I2C_EE, EEPROM_ADDRESS, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* While there is data to be read */
while(NumByteToRead)
{
if(NumByteToRead == 1)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_EE, DISABLE);
/* Send STOP Condition */
I2C_GenerateSTOP(I2C_EE, ENABLE);
}
/* Test on EV7 and clear it */
if(I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData(I2C_EE);
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_EE, ENABLE);
}
通过打断点发现
I2C_Send7bitAddress(I2C_EE, EEPROM_ADDRESS, I2C_Direction_Receiver); 发送完成后,scl时钟没有立刻产生,而是当
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); 判断完成后才产生,是因为 ADDR位被置位了???? 还是不敢确定 ——!
接下来第二次运行,I2C_Send7bitAddress(I2C_EE, EEPROM_ADDRESS, I2C_Direction_Receiver); 发送完成后加了10ms的软件延时(未超过25ms),这时
while(!I2C_CheckEvent(I2C_EE, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); 未判断成功,SCL时钟未产生,接下来 奇迹产生了, 程序居然跳到了 上一条指令 I2C_Send7bitAddress(I2C_EE, EEPROM_ADDRESS, I2C_Direction_Receiver); !!!!!!!!!!!!!!
然后运行完这句 未进while 就产生了 SCL时钟!!!
这是神马 状况??莫非是ST做的 出错纠正???
|