用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
# I2C操作 ## 使能设备树节点 arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts ~~~ &i2c0 { status = "okay"; ns2009: ns2009@48 { compatible = "nsiway,ns2009"; reg = <0x48>; }; sht21: sht21@40 { compatible = "sht21"; reg = <0x40>; }; atmel_mxt_ts@4a { compatible = "atmel,atmel_mxt_ts"; reg = <0x4a>; /*interrupt-parent = <&pio>; interrupts = <6 5 IRQ_TYPE_LEVEL_LOW>;*/ //省引脚,使用轮训方式 }; }; ~~~ ## BSP使用 内核中勾选: CONFIG_I2C_CHARDEV fex中使能对应twi号。 ## 使用i2c-tools ~~~ root@LicheePi:~# i2cdetect -l #查看系统使能的i2c总线,这里只有i2c0一个 i2c-0 i2c mv64xxx_i2c adapter I2C adapter root@LicheePi:~# i2cdetect -r -y 0 //检测总线上的设备。-y表示省去交互式 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: 40 -- -- -- -- -- -- -- UU -- 4a -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- ~~~ 这里的40,48,4a 分别是sht21温湿度传感器,ns2009电阻式触摸传感器,mxt336T电容式触摸传感器。 i2cdump可以dump出该设备的所有寄存器信息 ~~~ # i2cdump -y 0 0x48 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: ff ff ff ff ff ff ff ff 80 3c 3c 3b 3b 3c 3c 3b ........?<<;;<<; 10: 00 fa ff ff ff ff ff ff 80 00 00 00 00 00 00 00 .?......?....... 20: 7f ff ff ff ff ff ff ff 80 29 43 4e 63 6e 86 8b ?.......?)CNcn?? 30: ff ff ff ff ff ff ff ff 80 2b 45 4d 5d 74 74 7c ........?+EM]tt| 40: ff ff ff ff ff ff ff ff 80 49 48 48 49 49 48 49 ........?IHHIIHI 50: ff ff ff ff ff ff ff ff 80 3d 3c 3d 3d 3c 3d 3c ........?=<==<=< 60: 00 fe ff ff ff ff ff ff 80 00 00 00 00 00 00 00 .?......?....... 70: 7f ff ff ff ff ff ff ff 80 24 31 38 45 53 5a 67 ?.......?$18ESZg 80: 50 58 68 70 71 76 80 81 85 88 8e 96 9b a1 9d a9 PXhpqv?????????? 90: c7 c8 c5 be c1 bb c1 b7 b8 b9 b9 ba ba be c3 c1 ???????????????? a0: b1 ab ae b2 a4 9e a8 a8 a3 9d a9 a6 a0 97 9d a2 ???????????????? b0: 88 97 a3 a4 a7 a9 b2 ad b5 b4 b6 b4 b2 af b5 b6 ???????????????? c0: cf d4 cd cd cd d1 c7 ca c4 c0 ba bc bc c3 bc bf ???????????????? d0: dc dd de dc d9 d4 cf d5 d1 c7 c4 bd c2 b8 bb bd ???????????????? e0: c1 bb bf c5 be c8 c2 bb c1 b5 b6 b3 af bb bb c0 ???????????????? f0: 88 71 57 4f 50 45 40 3a 41 3c 45 41 3a 50 57 69 ?qWOPE@:A<EA:PWi ~~~ i2c上读写数据: ~~~ i2cset -y 1 0x40 0x00 0x13 i2cget -y 1 0x40 0x00 ~~~ ## sht21 传感器使用 ~~~ insmod sht21.ko echo sht21 0x40 > /sys/bus/i2c/devices/i2c-0/new_device ls /sys/class/hwmon/hwmon0 device name subsystem uevent humidity1_input power temp1_input cat /sys/class/hwmon/hwmon0/temp1_input 25201 #毫摄氏度,即25.201摄氏度 cat /sys/class/hwmon/hwmon0/humidity1_input 58872 #毫百分之1,即58.872%RH ~~~ ## 参考文档 https://blog.dbrgn.ch/2017/2/6/read-sht21-sensor-from-linux-raspberry-pi/ http://www.360doc.com/content/14/1008/11/7775902_415207889.shtml http://blog.csdn.net/AJ_chenrui/article/details/51202689