最近要操作eeprom,所以了解一下i2c-tool的使用方法,记录于此。

参考链接:

  http://www.myir-tech.com/bbs/thread-7567-1-1.html

  http://minix-i2c.blogspot.com/2013/07/using-i2c-tools-with-angstrom-linux-on.html

1、源码下载

  https://launchpad.net/ubuntu/+source/i2c-tools/3.0.3-5

2、解压,交叉编译

tar xjf i2c-tools-3.0.3.tar.bz2

cd i2c-tools-3.0.3-5/

make CC=arm-linux-gnueabihf-gcc

3、工具使用

将tools目录下的i2cdetect、i2cdump、i2cget、i2cset拷贝到开发板。

4、操作

1. 查看i2c总线
root@freescale ~$ i2cdetect -l
i2c-3 i2c i2c-gpio3 I2C adapter
i2c-0 i2c imx-i2c I2C adapter
i2c-1 i2c imx-i2c I2C adapter
i2c-2 i2c imx-i2c I2C adapter 2. 查看i2c总线上设备的地址
读取的结果显示地址为0x1a的设备忙,'UU'表示连接的设备忙.
root@freescale ~$ i2cdetect -y -r 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- root@freescale ~$ i2cdetect -y -r 3
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- 3、读写操作
对i2c-3,地址0x50的eeprom(at24c02)进行操作。 root@freescale ~$ i2cdump -f 3 0x50 c
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3, address 0x50, mode byte consecutive read
Continue? [Y/n] 由于设备忙,加上-f选项,表示force, -y 表示yes,否者就会出现上面的情况。 3.1 读取i2c-3上,地址为0x50的设备, at24c02共256字节
root@freescale ~$ i2cdump -f -y 3 0x50 c
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 01 02 03 39 34 3a 65 66 3a 31 35 3a 33 61 3a 65 ???94:ef:15:3a:e
10: 35 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5...............
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 3.1 读取i2c-3上,地址为0x50,寄存器地址为0的数据
root@freescale ~$ i2cget -f -y 3 0x50 0
0x01
root@freescale ~$ i2cget -f -y 3 0x50 0 c
0x01
root@freescale ~$ i2cget -f -y 3 0x50 0 b
0x01
root@freescale ~$ i2cget -f -y 3 0x50 0 w
0x0201 3.2 写入
a. 写进去的内容是16进制, 通过读取结果可知。
root@freescale ~$ i2cset -f -y 3 0x50 0 12 b
root@freescale ~$ i2cdump -f -y 3 0x50
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 0c 02 03 39 34 3a 65 66 3a 31 35 3a 33 61 3a 65 ???94:ef:15:3a:e
10: 35 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5...............
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ b. 能够识别0x开头的16进制作为参数,但是不能识别字符如 a, 或者'a'.
root@freescale ~$ i2cset -f -y 3 0x50 0 0xa b
root@freescale ~$ i2cdump -f -y 3 0x50
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 0a 02 03 39 34 3a 65 66 3a 31 35 3a 33 61 3a 65 ???94:ef:15:3a:e
10: 35 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5...............
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ c. 连续写一整块设备
root@freescale ~$ i2cset -f -y 3 0x50 0 0xa 0xb 0xc 0xd 0xe 0xf i
root@freescale ~$ i2cdump -f -y 3 0x50
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 0a 0b 0c 0d 0e 0f 65 66 3a 31 35 3a 33 61 3a 65 ??????ef:15:3a:e
10: 35 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5...............
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

Tony Liu

2016-10-11, Shenzhen

linux i2c tools的更多相关文章

  1. Linux I2C工具查看配置I2C设备【转】

    转自:http://blog.chinaunix.net/uid-26895763-id-3478882.html 在處理音訊相關的問題時,我通常會找個方法來讀寫codec中register的值.幸好 ...

  2. Linux I2C设备驱动编写(二)

    在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c_client.三者的关系也在上一节进行了描述.应该已经算是对Linux I2C子系统有了初步 ...

  3. 【转】Linux I2C设备驱动编写(二)

    原文网址:http://www.cnblogs.com/biglucky/p/4059582.html 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_drive ...

  4. Linux I2C(一)之常用的几种实例化(i2c_client ) 【转】

    转自:http://blog.csdn.net/lugandong/article/details/48092397 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 前言 方式 ...

  5. Linux+I2C总线分析(主要是probe的方式)

    Linux I2C 总线浅析 ㈠ Overview Linux的I2C体系结构分为3个组成部分: ·I2C核心: I2C核心提供了I2C总线驱动和设备驱动的注册.注销方法,I2C通信方法(即“algo ...

  6. Linux I2C总线控制器驱动(S3C2440)

    s3c2440的i2c控制器驱动(精简DIY),直接上代码,注释很详细: #include <linux/kernel.h> #include <linux/module.h> ...

  7. Linux I2C总线设备驱动模型分析(ov7740)

    1. 框架1.1 硬件协议简介1.2 驱动框架1.3 bus-drv-dev模型及写程序a. 设备的4种构建方法a.1 定义一个i2c_board_info, 里面有:名字, 设备地址 然后i2c_r ...

  8. Smart210学习记录-----Linux i2c驱动

    一:Linux i2c子系统简介: 1.Linux 的 I2C 体系结构分为 3 个组成部分: (1) I2C 核心. I2C 核心提供了 I2C 总线驱动和设备驱动的注册.注销方法,I2C 通信方法 ...

  9. linux i2c 设备节点读写

    最近需要操作24C02,封装了一下函数方便以后操作. 参考链接: https://my.oschina.net/handawei/blog/68526 http://blog.csdn.net/one ...

随机推荐

  1. MySQL添加字段和修改字段的方法

    添加表字段 alter table table1 add transactor varchar(10) not Null; alter table   table1 add id int unsign ...

  2. Java虚拟机(JVM)中的内存设置详解

    在一些规模稍大的应用中,Java虚拟机(JVM)的内存设置尤为重要,想在项目中取得好的效率,GC(垃圾回收)的设置是第一步. PermGen space:全称是Permanent Generation ...

  3. 如何快速查找IP归属地

    这两天遇到这么一个问题,就是查找一个IP的归属地.当然我会有一个IP段的分配列表,格式如下: 16777472    16778239    XX省 XX市 第一列是IP段的起始IP,第二列是IP段的 ...

  4. shadowColor表示阴影颜色,shadowBlur表示模糊等级

    绘制之前的准备工作: 1.在body中加入canvas标签,设置它的id.width.height,当然也可以动态设置它的宽高. <canvas id="mycanvas" ...

  5. PHP一般情况下生成的缩略图都比较不理想

    PHP用GD库生成高质量的缩略图片,PHP一般情况下生成的缩略图都比较不理想.今天试用PHP,GD库来生成缩略图.虽然并不100%完美.可是也应该可以满足缩略图的要求了.<?php $FILEN ...

  6. 按月将Windows日志导出至CSV文件

    # 这个月的第一天 #..........................................到这里之前是取当年第一天 #(Get-Date 0).AddYears((Get-Date). ...

  7. 【转】const和static readonly

    我们都知道,const和static readonly的确很像:通过类名而不是对象名进行访问,在程序中只读等等.在多数情况下可以混用.二者本质的区别在于,const的值是在编译期间确定的,因此只能在声 ...

  8. 用wget下载文件

    wget使用文档:https://www.gnu.org/software/wget/manual/wget.html 最开始常用的比如: wget -O  /e/movie.mp4 http://w ...

  9. vi 编辑器常用命令

    VI编辑器可以分为3种状态,它们分别是命令模式.输入模式以及末行模式,VI运行后默认进入命令模式. 命令模式:控制屏幕光标的移动,字符.单词或行的删除.替换,复制粘贴数据以及由此进入插入模式和末行模式 ...

  10. 利用SpannableString设置文本

    private void setTips(){ String big = "大字深色"; String small = "小字淡色"; Spannable ti ...