I2C 设备地址求解

来源:互联网 发布:mac桌面壁纸文件夹 编辑:程序博客网 时间:2024/06/07 09:16
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
原创粉丝点击