主机通过SMBus读数据时,怎么判断读到的是正确的?
读取数据时,有时候会读到错误的数据,比如0x00或0xff等。怎么校验读到的温度电压电流等数据是正确的呢?
首先可以通过ACK bit来确认。
其次,SMBus一般都是支持PEC校验的。
哦,PEC校验在哪个文档里有介绍?
这是SMBus的标准规范。
5.4.1. Packet error checking implementation
The SMBus must accommodate any mixture of devices that support Packet Error Checking and devices
that do not. A device that acts as a slave and supports the PEC must always be prepared to perform the
slave transfer with or without a PEC, verify the correctness of the PEC if present, and only process the
message if the PEC is correct. Implementations are encouraged to issue a NACK if the PEC is present but
not correct.
5.4.1.3. Slave implementation
A slave device that implements Packet Error Checking must be prepared to receive and transmit data with
or without a PEC. During a slave receive transfer, after the device has identified the protocol and
command must accept and check the additional PEC for validity.
During a slave transmit transfer, the slave transmitter must respond to additional clocks after the last byte
transfer and furnish a PEC to the master receiver requesting it.
Each bus transaction requires a Packet Error Code (PEC) calculation by both the transmitter and receiver
within each packet. The PEC uses an 8-bit cyclic redundancy check (CRC-8) of each read or write bus
transaction to calculate a Packet Error Code (PEC). The PEC may be calculated in any way that conforms
to a CRC-8 represented by the polynomial, C(x) = x8 + x2 + x1 + 1 and must be calculated in the order of
the bits as received.
Calculating the PEC for transmission or reception is implemented in a method chosen by the device
manufacturer. It is possible to perform the check with low-cost hardware or firmware algorithm that could
process the message bit-by-bit or with a byte-wise look-up table. The SMBus web page provides some
example CRC-8 methods.
The PEC is appended to the message as dictated by the protocols in section 5.5. The PEC calculation
includes all bytes in the transmission, including address, command and data. The PEC calculation does not
include ACK, NACK, START, STOP nor Repeated START bits. This means that the PEC is computed
over the entire message from the first START condition.
Whether a device implements packet error checking may be determined by the specification revision code
that is present in the SpecificationInfo() command for a Smart Battery, Smart Battery Charger or Smart
Battery Selector. See these individual specifications for exact revision coding identities. It may also be
discovered in the UDID, defined in section 5.6.1, for other devices.
谢谢回复,看来还是比较复杂的。