STM32 I2C读取额外的“空”字节

时间:2021-02-28 06:52:46

I am reading BMP180 pressure sensor on STM32 and well, it works, but, watching the transfer on the analyzer I can always see an extra empty byte read.

我正在STM32上读取BMP180压力传感器,它很有效,但是,看着分析仪上的传输,我总能看到一个额外的空字节读取。

I am almost sure, it is because I give the I2C_GenerateSTOP() only after I I2C_ReceiveData() - this is kind of logical, but not as all the examples go. There, you call I2C_GenerateSTOP() even before waiting for the I2C_EVENT_MASTER_BYTE_RECEIVED of the last byte.

我几乎可以肯定,这是因为我只在I2C_ReceiveData()之后给出了I2C_GenerateSTOP() - 这是合乎逻辑的,但并不像所有的例子那样。在那里,甚至在等待最后一个字节的I2C_EVENT_MASTER_BYTE_RECEIVED之前调用I2C_GenerateSTOP()。

Now, if I do as the examples go, the readout is not stable: it works few times, then does not anymore: wait for I2C_EVENT_MASTER_MODE_SELECT after I2C_GenerateSTART() times out.

现在,如果我按照示例去做,读出不稳定:它工作几次,然后不再:在I2C_GenerateSTART()超时后等待I2C_EVENT_MASTER_MODE_SELECT。

I tried to search various examples but was not able to find any clue how to resolve this.

我试图搜索各种示例,但无法找到解决此问题的任何线索。

Could anybody help ?

有人可以帮忙吗?

1 个解决方案

#1


I think the errata sheet for some of their chips describes this behavior

我认为他们的一些芯片的勘误表描述了这种行为

Description
When the EV7, EV7_1, EV6_1, EV6_3, EV2, EV8, and EV3 events are not managed before the current byte is being transferred, problems may be encountered such as receiving an extra byte, reading the same data twice or missing data.

描述当在传输当前字节之前未管理EV7,EV7_1,EV6_1,EV6_3,EV2,EV8和EV3事件时,可能会遇到问题,例如接收额外字节,读取相同数据两次或丢失数据。

Workaround is there too
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/errata_sheet/CD00190234.pdf

也有解决方法http://www.st.com/st-web-ui/static/active/en/resource/technical/document/errata_sheet/CD00190234.pdf

#1


I think the errata sheet for some of their chips describes this behavior

我认为他们的一些芯片的勘误表描述了这种行为

Description
When the EV7, EV7_1, EV6_1, EV6_3, EV2, EV8, and EV3 events are not managed before the current byte is being transferred, problems may be encountered such as receiving an extra byte, reading the same data twice or missing data.

描述当在传输当前字节之前未管理EV7,EV7_1,EV6_1,EV6_3,EV2,EV8和EV3事件时,可能会遇到问题,例如接收额外字节,读取相同数据两次或丢失数据。

Workaround is there too
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/errata_sheet/CD00190234.pdf

也有解决方法http://www.st.com/st-web-ui/static/active/en/resource/technical/document/errata_sheet/CD00190234.pdf