STM32 I2C1 SR1 寄存器上未设置起始位
我正在尝试对 stm32 进行编程以与我的 i2c EEprom 进行通信,但似乎每次我都会说:
I2C_GenerateSTART(I2C1, ENABLE);
while( !(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) ); the code hangs here
我使用调试器进行了调试,发现 SR1 位 0 标志(这是起始位生成标志)未设置这就是代码挂起的原因。我可以在示波器中看到生成了起始位,并且有时会起作用。当我尝试连续进行多次写入时,它通常会中断。我检查了硬件,一切看起来都很好。我检查了在 i2c 总线上运行的频率,它在 24lc1025 eeprom 内为 100Khz。
任何想法,
谢谢
I am trying to program the stm32 to talk to my i2c EEprom, but it seems like everytime I say:
I2C_GenerateSTART(I2C1, ENABLE);
while( !(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) ); the code hangs here
I went through with the debugger and I found that the SR1 bit 0 flag (which is the start bit generated flag) is not set which is why the code hangs. I can see in the oscilloscope that the start bit was generated and this works sometimes. it usually breaks when I tried to do several writes in a row. I checked the HW is everything looks fine I checked the frequency that I am running on the i2c bus it is 100Khz well within the 24lc1025 eeprom.
any ideas,
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
既然您说当您连续进行多次写入时,这通常会中断,因此您可能需要确保没有违反 STM32 数据表中 I2C_CR1 控制中的
STOP
位的注释登记:设置
STOP
位后,您需要确保硬件已将其清除,然后再写入下一个START
位。Since you say that this usually breaks when you're doing several writes in a row, you might want to ensure that you're not violating this note in the STM32 datasheet for the
STOP
bit in the I2C_CR1 control register:Once you set the
STOP
bit you need to make sure that the hardware has cleared it before you write the nextSTART
bit.检查您设备的勘误表(从 ST 网站获取)。 STM32在I2C实现上存在很多bug。勘误表为它们提供了软件解决方法。
Check the Errata for your device (get it from the ST website). The STM32 has a lot of bugs in the I2C implementation. The errata gives software workarounds for them.
另外,当使用 STM32 平台通常提供的驱动程序源文件时,不要忘记阅读标题!它们非常有帮助,特别是对于不知道从哪里开始的新手(像我一样)。
在这种情况下,您将查看 stm32f4xx_i2c.c
Also, when using the driver source files typically provided with STM32 platforms, don't forget to read through the headers! They can be very helpful, especially for novices (like me) who aren't sure where to start.
In this case, you would be looking at stm32f4xx_i2c.c