厦门莫格电气自动化有限公司销售
GE 531X171TMAAEG2
欢迎来电咨询!
531X171TMAAEG2
531X171TMAAEG2
您迈开询价的一小步,我还您成功的一大步。
1). 简介
I2C是嵌入式设备***为常用的接口之一,常用于如下面这些应用场景,因此本文就基于嵌入式Linux演示在User Space进行I2C设备调试。
- Digital to Analog converter
- EEPROM
- Real Time Clock
- Touch screen LCD
- Audio codec
本文所演示的平台来自于Toradex ApalisiMX6Q ARM嵌入式平台,这是一个基于NXP iMX6Q ARM处理器,支持四核心Cortex-A9。
2. 准备
a).Apalis iMX6Q ARM核心版配合Apalis Ixora载板,连接调试串口UART1到开发主机方便调试,同时配置好Ubuntu开发主机开发环境,具体操作方法可以参考这里。
b).Apalis iMX6Q系统使用Toradex Linux Release V2.6.1,***和更新方法请参考这里。
3). I2C总线user space操作命令测试
a). Apalis iMX6Q核心版默认定义提供了三个I2C总线可供外部使用(i2c-2为核心板内部电源管理使用),如下所示,其中i2c-1为通用I2C接口;i2c-0为DDC接口,用于连接HDMI DDC/EDID接口,不能用做通用I2C接口;而i2c-3通常用于连接camera接口使用,不过也可以用做通用I2C接口。
b). 本文演示示例则通过读写ApalisIxora载板连接在i2c-1总线上面的2Kb EEPROM
c). User Space下通过I2C tools直接操作i2c-1总线进行访问EEPROM
./ 查看Apalis iMX6Q的所有I2C总线
---------------------------------
root@apalis-imx6:~# ls -l /dev/i2c-*
crw------- 1 root root 89, 0 4??月 26 06:52 /dev/i2c-0
crw------- 1 root root 89, 1 4??月 26 06:52 /dev/i2c-1
crw------- 1 root root 89, 2 4??月 26 06:52 /dev/i2c-2
crw------- 1 root root 89, 3 4??月 26 06:52 /dev/i2c-3
--------------------------------
./ 查看i2c-1总线上面的设备
可以看到在0x50和0x68两个地址上面挂有设备,0x68显示为UU意味着这个设备被kernel driver占用,通常不能从user space探查,这里结合Apalis iMX6Q手册可以得知挂载的为外部RTC设备;而0x50则为我们所需要测试的EEPROM设备
--------------------------------
--------------------------------
./ dump 0x50 EEPROM全部寄存器地址0-0xff,初始状态下每个寄存器地址保存的数值都是0xff
--------------------------------
--------------------------------
./使用i2cset和i2cget来写和读EEPROM特定寄存器地址
--------------------------------
// 向EEPROM 0x00寄存器地址写入0x01
root@apalis-imx6:/home# i2cset 1 0x50 0x000x01 b
WARNING! This program can confuse your I2Cbus, cause data loss and worse!
DANGEROUS! Writing to a serial EEPROM on amemory DIMM
may render your memory USELESS and makeyour system UNBOOTABLE!
I will write to device file /dev/i2c-1,chip address 0x50, data address
0x00, data 0x01, mode byte.
Continue? [y/N] y
// 读取EEPROM 0x00寄存器地址
root@apalis-imx6:/home# i2cget 1 0x50 0x00b
……
0x01
--------------------------------
d). User Space下通过I2C tools读取i2c-1总线进行访问RTC芯片
./Apalis Ixora载板外部RTC芯片使用ST m41t00 芯片,其内部集成8 byte寄存器用于存储时间相关信息,格式如下:
--------------------------------
1st byte: seconds register
2nd byte: minutes register
3rd byte: century/hours register
4th byte: day register
5th byte: date register
6th byte: month register
7th byte: years register
8th byte: control register
--------------------------------