打印
[STM8]

stm8l的I2C通讯中PEC如何使用?

[复制链接]
3189|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zdaly|  楼主 | 2015-5-20 09:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题,请教各位坛友,stm8l的I2C通讯中PEC如何使用?Datasheet说到的不多:
Configurable PEC (packet error checking) generation or verification:
– PEC value can be transmitted as last byte in Tx mode
– PEC error checking for last received byte
目前也没有找到可以的参考例程,请各位坛友帮忙指点一下,谢谢.
沙发
zdaly|  楼主 | 2015-5-20 10:15 | 只看该作者
Packet error checking
A PEC calculator has been implemented to improve the reliability of communication. The PEC is calculated by using the C(x) = x8 + x2 + x + 1 CRC-8 polynomial serially on each bit.
• PEC calculation is enabled by setting the ENPEC bit in the I2C_CR1 register. PEC is a
CRC-8 calculated on all message bytes including addresses and R/W bits.
– In transmission: set the PEC transfer bit in the I2C_CR1 register after the TxE
event corresponding to the last byte. The PEC will be transferred after the last
transmitted byte.
– In reception: set the PEC bit in the I2C_CR2 register after the RxNE event
corresponding to the last byte so that the receiver sends a NACK if the next
received byte is not equal to the internally calculated PEC. PEC must be set
before the ACK pulse of the current byte reception. In case of Master-Receiver, a
NACK must follow the PEC whatever the check result.
• A PECERR error flag/interrupt is also available in the I2C_SR2 register.
• If DMA and PEC calculation are both enabled:-
– In transmission: when the I2C interface receives an EOT signal from the DMA
controller, it automatically sends a PEC after the last byte.
– In reception: when the I2C interface receives an EOT_1 signal from the DMA
controller, it will automatically consider the next byte as a PEC and will check it. A
DMA request is generated after PEC reception.
• To allow intermediate PEC transfers, a control bit is available in the I2C_ITR register
(LAST bit) to determine if it is really the last DMA transfer or not. If it is the last DMA
request for a master receiver, a NACK is automatically sent after the last received byte.
• PEC calculation is corrupted by an arbitration loss.

使用特权

评论回复
板凳
可可球| | 2015-5-20 10:35 | 只看该作者
IIC在对方接受到信号后会有应答的

使用特权

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

本版积分规则

18

主题

419

帖子

0

粉丝