IoTGateway/BSP/Android/Gettingstarted/How to use I2C
From ESS-WIKI
Test
Check i2c busses
- Usage: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]
#i2cdetect -l i2c-0 i2c 21a0000.i2c I2C adapter i2c-1 i2c 21a4000.i2c I2C adapter i2c-2 i2c 21a8000.i2c I2C adapter
Check devices on i2c-2 bus
#i2cdetect -y -r 2 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: UU UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- UU --
Dump I2C device register content
- Usage: i2cdump [-f] [-y] [-r first-last] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]
# i2cdump -y -f 2 0x76 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: 54 00 80 43 40 40 40 00 00 00 00 00 00 00 ff ff T.?C@@@S........ 10: 85 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ?............... 20: 00 00 00 18 ff ff ff ff ff ff ff ff ff ff ff ff ...?............ 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ 80: 54 00 80 43 40 40 40 53 00 00 00 00 00 00 ff ff T.?C@@@S........ 90: 85 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ?............... a0: 00 00 00 18 ff ff ff ff ff ff ff ff ff ff ff ff ...?............ b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
Read a single byte
- Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
# i2cget -f -y 2 0x76 7 0x00
Change its value and verify it
- Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]
# i2cset -f -y 2 0x76 7 0x53 # i2cget -f -y 2 0x76 7 0x53