打印

请大侠帮忙!I2C的SCL的产生问题!

[复制链接]
3925|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
kavieen|  楼主 | 2011-8-3 19:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
I2c, TE, AD, ST, ev
请教大侠们一个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做的 出错纠正???



沙发
kavieen|  楼主 | 2011-8-3 20:02 | 只看该作者
莫非是程序跑乱了?? 重复了几次,程序依旧跳到上一条指令。。。。。 请大侠们指点,急切想弄明白 SCL时钟什么时候产生~~~~~!!

使用特权

评论回复
板凳
kavieen|  楼主 | 2011-8-6 21:34 | 只看该作者
最后发现时ADDR位被清除后发出的SCL时钟,调试器真的容易出错~~~看来了I2c的纠错机制,也提到第二次自动发送问题~~~不过还是不太确定这个~~~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

20

帖子

1

粉丝