QNX下i2c工具使用

本文介绍了如何使用i2ctool在QNX系统中对I2C总线进行操作,包括列出总线、扫描设备、读取和写入16位寄存器值,并提供了具体命令示例。例如,通过'i2ctool/dev/i2c1read0x620x0021endian1'读取设备数据,以及'i2ctool/dev/i2c4write0x340x320020x1fendian1'写入寄存器。
摘要由CSDN通过智能技术生成

系统:qnx

1.使用

use i2ctool
usage: i2ctool

options:
list:         list all the valid i2c buses
scan:         list all the valid address in the specified i2c bus
read:         read mode
write:        write mode
endian:       little/big endian, 0: little, 1: big
verbosity:    log level

for example:
i2ctool list
i2ctool /dev/i2c1 scan
i2ctool /dev/i2c1 read 0x62 0x00 2 1
i2ctool /dev/i2c1 read 0x62 0x00 2 1 endian 1
i2ctool /dev/i2c1 write 0x62 0x00 2 0xc4 endian 1

i2ctool /dev/i2c1 read   0x62          0x00                2                 1                endian 1
            |              |             |                 |                 |                       |
            |              |             |                 |                 |                       |
            |              |             |                 |                 |                       |
        [i2c bus]    [slave address] [register addr] [reg len (2 bytes)] [read len (1 byte)]   [Big endian]
            
i2ctool /dev/i2c1  write  0x62          0x00               2               0xc4               endian 1
            |              |             |                 |                 |                       |
            |              |             |                 |                 |                       |
            |              |             |                 |                 |                       |
        [i2c bus]    [slave address] [register addr] [reg len (2 bytes)] [write value]         [Big endian]

注意:
1.slave address为7bit值,如果需要读取的寄存器位16位,则reg_len为2 byte,
2.cci总线和i2c总线使用的方式一样

2.扫描总线器件

i2ctool /dev/i2c4 scan

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- 34 -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 

在代码中也可以直接使用如

	system("i2ctool /dev/i2c2 scan");
	system("i2ctool /dev/cci2 scan");

3.读取16位寄存器的值

i2ctool /dev/i2c4 read 0x34 0x42 2 1 endian 1
argc: 9, endian: 1, reg_addr: 0x42, reg_size: 1
read slave_address: 0x34, register_address: 0x4200, reg_addr_len: 2, size: 1
R data:
reg(0x42): 0x30
R: success

4.写入总线寄存器

i2ctool /dev/i2c4 write 0x34 0x3200 2 0x1f endian 1
write slave_address: 0x34 , register_address: 0x32, reg_addr_len: 2
write data_len: 1, data: 0x1f 
W: success 
read slave_address: 0x34 , register_address: 0x3200, reg_addr_len: 2, size: 1
R data:
reg(0x34): 0x01f
R: success
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值