I2C接口调试指南

I2C接口应用广泛,很多设备像触屏,电量检测,摄像头接口,传感器芯片等等都经常用到。在Connectcore的U-Boot里都集成有i2c的调试工具。

调试命令集锦

1、扫描总线 根据你有几条I2C总线,相关代号从0开始。

i2cdetect -ry 0

这样就会出来所有的I2C芯片的地址,比如OV的摄像头常见7位地址是36。提示:若 i2cdetect 显示 UU 而非 36,说明驱动已占用设备,需先 rmmod ov2740 再扫描。

2、读取16位寄存器0x300a(Chip ID) 在驱动ov2740.c内可以看到各寄存器的意义,OV2740的寄存器地址是16位,而i2cget默认使用8位寻址,所以一般用i2ctransfer读。 其中300a是chip ID寄存器,存放着设备名称,也就是2740。

# 读取16位寄存器0x300a(Chip ID)
i2ctransfer -y 0 w2@0x36 0x30 0x0a r2
# w2	Write 2 bytes(写入2个字节),即发送 0x30 0x0a 到设备 0x36;r2	Read 2 bytes(读取2个字节)	从设备读取2个字节数据
# 预期输出:0x27 0x40,表示0x300a寄存器值为0x2740
# 读取Mode Select寄存器(0x0100)
i2ctransfer -y 0 w2@0x36 0x01 0x00 r1 
# 返回0x00或0x01

linux下设备树查询


i2croot@ccmp25-dvk:~# cat /proc/device-tree/soc\@0/bus\@42080000/i2c\@40140000/name
root@ccmp25-dvk:~# cat /proc/device-tree/soc\@0/bus\@42080000/i2c\@40120000/ov2740_mipi\@36/status
root@ccmp25-dvk:~# cat /proc/device-tree/soc\@0/bus\@42080000/i2c\@40120000/ov2740_mipi\@36/clocks
root@ccmp25-dvk:~# cat /proc/device-tree/soc\@0/bus\@42080000/i2c\@40120000/ov2740_mipi\@36/compatible
root@ccmp25-dvk:~# cat /proc/device-tree/soc\@0/bus\@42080000/i2c\@40120000/name
i2cr