I2C
— 两线串行协议¶
使用示例::(python)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # coding=utf-8
# This is a sample Python script.
from driver import I2C
print("-------------------i2c test--------------------")
i2c = I2C()
i2c.open("pca9544")
regval = bytearray(1)
regval[0] = 0x5
print(regval)
ret = i2c.write(regval)
print(ret)
i2c.close()
print("-------------------i2c test--------------------")
|
配置信息::(json)¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # coding=utf-8
# This is a sample cjson file.
{
"version": "1.0.0",
"io": {
"pca9544": {
"type": "I2C",
"port": 1,
"addrWidth": 8,
"freq": 100000,
"mode": "master",
"devAddr": 112
}
},
"debugLevel": "DEBUG"
}
|
操作函数¶
-
open
(jsonConfigPath, type)¶ 打开I2C并根据json文件创建I2C实例
-
close
()¶ 关闭I2C实例
-
read
(dataBuffer)¶ 主动读取指定bytes的I2C数据。该函数为阻塞函数,会一直等待读取指定bytes的数据
-
write
(dataBuffer)¶ 发送数据,该函数为阻塞函数,I2C发送完成后才会返回
-
readReg
(addr, dataBuffer)¶ 主动向寄存器地址memaddr读取指定bytes的I2C数据。该函数为阻塞函数,会一直等待读取指定bytes的数据
-
writeReg
(addr, dataBuffer)¶ 向寄存器地址memaddr发送数据,该函数为阻塞函数,I2C发送完成后才会返回