I2C从器件地址

指南针芯片和加速度、角加速度芯片用到了I2C通信。其中I2C的从器件地址(我只用到了7位的)的组成如下:

1byte = 7bit地址 + 1bit读写标志

注:1bit读写标志中,0-发送数据(写),1-请求数据(读)。

有的芯片手册上给的地址包括了1bit读写标志,有的数据手册上给的地址不包括1bit读写标志。举例如下:

(1) 3轴数字指南针芯片HMC5881L(3-Axis Digital Compass)
The default (factory) HMC5883L 7-bit slave address is 0x3C for write operations, or 0x3D for read operations.

可以看到,这个给的地址已经包含了读写标志位,其中:

a)    0x3C = 00111100b   :这个是写操作时发送的地址字节。

b)    0x3D = 00111101b   :这个是读操作时发送的地址字节。

(2)3轴数字输出陀螺仪芯片L3G4200D(three-axis digital output gyroscope)

The slave address (SAD) associated with the L3G4200D is 110100xb. The SDO pin can be used to modify the least significant bit (LSb) of the device address. If the SDO pin is connected to the voltage supply, LSb is ‘1’ (address 1101001b). Otherwise, if the SDO pin is connected to ground, the LSb value is ‘0’ (address 1101000b).

可以看到,7位地址跟SDO的电平高低有关:

a)    当SDO引脚拉高时,从地址是0x69 = 1101001b。写操作应该发送的字节是 (0x69<<1)|0x00,读操作应该发送的字节是 (0x69<<1)|0x01。

b)    当SDO引脚拉低时,从地址是0x68 = 1101000b。写操作应该发送的字节是 (0x68<<1)|0x00,读操作应该发送的字节是 (0x68<<1)|0x01。

I2C总线设备地址:

设备地址标识外设在总线上的唯一性,每一个外设都有唯一的设备地址,设备地址由原理图和芯片手册共同定义!CPU通过设备地址来访问到I2C总线上的某个外设!类似"学生的学号"

例如:
以AT24C02存储器为例:
通过查阅芯片手册发现
设备地址=01010A2A1A0(去掉R/W位,高位补0),硬件将A2A1A0都接地=》设备地址=01010000=0x50
再次得到:
如果CPU读设备,那么读设备地址=设备地址<<1 | 1=>
1010A2A1A01=>10100001=>0xa1
如果CPU写设备,那么写设备地址=设备地址<<1 | 0 = 0xa0

而有些芯片是没有直接给出I2C设备地址的,只有读写设备地址

例如MT9P031 芯片手册

Slave Address
The 8-bit address of a two-wire serial interface device consists of 7 bits of address and 1
bit of direction. A “0” in the LSB (least significant bit) of the address indicates write mode
(0xBA), and a “1” indicates read mode (0xBB).
 

如此就可以按照上面的方法,倒着推出I2C设备地址。

MT9P031 图像传感器
读0xBB=10111011  
写0xBA=10111010
0101 1101 = 0x5d 
设备地址为 0x5d

加粗加黑的地方意思是:这个从地址其实说白了还是跟硬件连接有关。不一定是死的。

猜你喜欢

转载自blog.csdn.net/u012839187/article/details/83744879
I2C
今日推荐