STM32 I2C1 SR1 寄存器上未设置起始位

发布于 2024-08-27 07:07:19 字数 394 浏览 7 评论 0原文

我正在尝试对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千柳 2024-09-03 07:07:19

既然您说当您连续进行多次写入时,这通常会中断,因此您可能需要确保没有违反 STM32 数据表中 I2C_CR1 控制中的 STOP 位的注释登记:

注意:当设置STOPSTARTPEC位时,软件不得执行任何写操作
在该位被硬件清零之前访问I2C_CR1。否则有风险
设置第二个 STOPSTARTPEC 请求。

设置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:

Note: When the STOP, START or PEC bit is set, the software must not perform any write
access to I2C_CR1 before this bit is cleared by hardware. Otherwise there is a risk of
setting a second STOP, START or PEC request.

Once you set the STOP bit you need to make sure that the hardware has cleared it before you write the next START bit.

失眠症患者 2024-09-03 07:07:19

检查您设备的勘误表(从 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.

迷你仙 2024-09-03 07:07:19

另外,当使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文