linux i2c tools
最近要操作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的更多相关文章
- Linux I2C工具查看配置I2C设备【转】
转自:http://blog.chinaunix.net/uid-26895763-id-3478882.html 在處理音訊相關的問題時,我通常會找個方法來讀寫codec中register的值.幸好 ...
- Linux I2C设备驱动编写(二)
在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c_client.三者的关系也在上一节进行了描述.应该已经算是对Linux I2C子系统有了初步 ...
- 【转】Linux I2C设备驱动编写(二)
原文网址:http://www.cnblogs.com/biglucky/p/4059582.html 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_drive ...
- Linux I2C(一)之常用的几种实例化(i2c_client ) 【转】
转自:http://blog.csdn.net/lugandong/article/details/48092397 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 前言 方式 ...
- Linux+I2C总线分析(主要是probe的方式)
Linux I2C 总线浅析 ㈠ Overview Linux的I2C体系结构分为3个组成部分: ·I2C核心: I2C核心提供了I2C总线驱动和设备驱动的注册.注销方法,I2C通信方法(即“algo ...
- Linux I2C总线控制器驱动(S3C2440)
s3c2440的i2c控制器驱动(精简DIY),直接上代码,注释很详细: #include <linux/kernel.h> #include <linux/module.h> ...
- Linux I2C总线设备驱动模型分析(ov7740)
1. 框架1.1 硬件协议简介1.2 驱动框架1.3 bus-drv-dev模型及写程序a. 设备的4种构建方法a.1 定义一个i2c_board_info, 里面有:名字, 设备地址 然后i2c_r ...
- Smart210学习记录-----Linux i2c驱动
一:Linux i2c子系统简介: 1.Linux 的 I2C 体系结构分为 3 个组成部分: (1) I2C 核心. I2C 核心提供了 I2C 总线驱动和设备驱动的注册.注销方法,I2C 通信方法 ...
- linux i2c 设备节点读写
最近需要操作24C02,封装了一下函数方便以后操作. 参考链接: https://my.oschina.net/handawei/blog/68526 http://blog.csdn.net/one ...
随机推荐
- iOS5中UIViewController的新方法
iOS5中UIViewController的新方法 前言 在苹果的 WWDC2011 大会视频的<Session 101 - What's New in Cocoa> 和<Sessi ...
- ARC指南3 - @property
本章介绍引入ARC后@property的使用,跟ARC之前的还是很不一样的 一..h和.m文件的变化说明 1.对于.h头文件,主要是将属性定义由retain变为strong @property ( ...
- MatLab GUI Change Size 改变界面大小
在MatLab做的GUI界面,我们有时候会希望界面的大小能改变,并且上面的控件也会跟着界面变大或者缩小,MatLab在这方面做的非常好,不像Qt的GUI那样实现起来那么麻烦,只需要把界面的属性Resi ...
- FZU 2032 高精度小数加法
题目描写很没意思..就是说给出n个小数 求它们的总和 因为给出的小数点后最多16位而要求保存至12位 而能直接使用的最精确的double只能到12位 于是13的进位可能被忽略 于是不可以用double ...
- mongodb 3.2 分片部署步骤
#linux 网络优化1. 文件中/etc/sysctl.conf, 加入net.core.somaxconn = 2048fs.file-max = 2000000fs.nr_open = 2000 ...
- PHP 使用 GET 传递数组变量
PHP 代码: <?php print_r($_GET['tag_name']); URL: http://127.0.0.16/get.php?tag_name[]=送货快&tag_n ...
- dp和px的转换
/** * dp转px * @param context * @param dp * @return */ public static int dp2px(Context context, float ...
- 常用的API接口,返回JSON格式的服务API接口
物流接口 快递接口: http://www.kuaidi100.com/query?type=快递公司代号&postid=快递单号 ps:快递公司编码:申通="shentong&qu ...
- Oracle 数据库安装
下载 www.oracle.com ->Downloads -> Oracle Database 安装: 解压到同一文件夹下 仅安装数据库软件 单实例数据库安装 企业版 oracle基目录 ...
- Java:按值传递还是按引用传递详细解说
前天在做系统的时候被Java中参数传递问题卡了一下,回头查阅了相关的资料,对参数传递问题有了新的了解和掌握,但是有个问题感觉还是很模糊,就是Java中到底是否只存在值传递,因为在查阅资料时,经常看到有 ...