24 IIC(二)SMBus协议

发布时间 2023-05-07 13:18:33作者: 人民广场的二道贩子

SMBus协议:http://www.smbus.org/specs/

1. SMBus简介

SMBus:System Manage Bus,系统管理总线

SMBus是基于IIC协议发展而来,SMBus要求比IIC更加严格,是其子集

2. SMBus与IIC的区别

  • VDD的极限值不一样

    IIC:范围广

    SMBus:1.8v-5v

  • 时钟频率和clock streting

    IIC:无限制

    SMBus:时钟频率最小为10KHz,clock streting也存在限制

  • 地址应答

    IIC:无强制要求

    SMBus:必须有应答

  • 重复发出S信号

    SMBus可以在一帧数据中进行读写的转换,而不发送停止信号

3. SMbus协议

3.1 符号

S     (1 bit) : Start bit(开始位)
Sr    (1 bit) : 重复的开始位
P     (1 bit) : Stop bit(停止位)
R/W#  (1 bit) : Read/Write bit. Rd equals 1, Wr equals 0.(读写位)
A, N  (1 bit) : Accept and reverse accept bit.(回应位)
Address(7 bits): I2C 7 bit address. Note that this can be expanded as usual to
                get a 10 bit I2C address.
                (地址位,7位地址)
Command Code  (8 bits): Command byte, a data byte which often selects a register on
                the device.
                (命令字节,一般用来选择芯片内部的寄存器)
Data Byte (8 bits): A plain data byte. Sometimes, I write DataLow, DataHigh
                for 16 bit data.
                (数据字节,8位;如果是16位数据的话,用2个字节来表示:DataLow、DataHigh)
Count (8 bits): A data byte containing the length of a block operation.
				(在block操作总,表示数据长度)
[..]:           Data sent by I2C device, as opposed to data sent by the host
                adapter.
                (中括号表示I2C设备发送的数据,没有中括号表示host adapter发送的数据)

3.2 SMBus Quick Command

在SBMbus Quick Command中R/W被用来表示开关之类的含义

3.3 SMBus Receive Byte

读取一字节数据后,不回应

I2C-tools中的函数:i2c_smbus_read_byte()

3.4 SMBus Send Byte

发送一字节数据

I2C-tools中的函数:i2c_smbus_write_byte

3.5 SMBbus Read Byte

command code一般用来表示读取的设备的寄存器地址

注意:SMBus Read Byte和SMBus Receive Byte的区别

SMBus Read Byte读取指定位置的数据;而SMBus Receive Byte则是直接读取发送来的数据

I2C-tools中的函数:i2c_smbus_read_byte_data

3.6 SMBus Read Word

I2C-tools中的函数:i2c_smbus_read_word_data

3.7 SMBus Write Byte

注意:SMBus Write Byte和SMBus Send Byte

SMBus Write Byte写指数据到指定位置;而SMBus Send Byte则是直接发送数据

I2C-tools中的函数:i2c_smbus_write_byte_data

3.8 SMBus Write Word

I2C-tools中的函数:i2c_smbus_write_word_data

3.9 SMBus Block Read

先从设备处读到Block Count。表示后续需要读取的字节数。

I2C-tools中的函数:i2c_smbus_read_block_data

3.10 SMBus Block Write

I2C-tools中的函数:i2c_smbus_write_blcok_data

3.11 I2C Block Read

IIC也能实现Block读,不过它的区别在于。IIC的block读不存在Block Count位

I2C-tools中的函数:i2c_smbus_read_i2c_block_data

3.12 I2C Block Write

I2C-tools中的函数:i2c_smbus_write_i2c_block_data

3.13 SMBus Block Write - Block Read Process Call

3.14 Packet Error Checking (PEC)

PEC是一种错误校验码,如果使用PEC,那么在P信号之前,数据发送方要发送一个字节的PEC码(它是CRC-8码)。