This service provides an ability to manage I2C peripherals on devices remotely.
It is possible to call this service programmatically via serial, HTTP/RESTful,
Websocket, MQTT or other transports
(see RPC section) or via the mos
tool.
Below is a list of exported RPC methods and arguments:
Scan the I2C bus, return a list of available device addresses. Arguments: none.
Example usage:
mos call I2C.Scan
[
31 # There is only 1 device with address 31 attached to the I2C bus
]
Read data from the I2C device. Arguments:
{
"addr: 31, // Required. Device address.
"len": 2 // Required. Number of bytes to read.
}
Reply:
{
// Hex-encoded data. Each byte is encoded as XX hex code, e.g. 0x00 0x1d:
"data_hex": "001d"
}
Example usage:
mos call I2C.Read '{"addr": 31, "len": 2}'
{
"data_hex": "001d"
}
Write data to the I2C device. Arguments:
{
"addr: 31, // Required. Device address.
"data_hext": "1f3c6a" // Required. Hex-encoded data to write
}
Example usage (showing failed write):
mos call I2C.Write '{"addr": 31, "data_hex": "1f3c6a"}'
Error: remote error: I2C write failed
Read 1-byte register value. Arguments:
{
"addr: 31, // Required. Device address.
"reg": 0 // Required. Register number.
}
Example usage:
mos call I2C.ReadRegB '{"addr": 31, "reg": 0}'
{
"value": 0
}
Write 1-byte register value. Arguments:
{
"addr: 31, // Required. Device address.
"reg": 0, // Required. Register number.
"value": 0 // Required. 1-byte value to write.
}
Example usage:
mos call I2C.WriteRegB '{"addr": 31, "reg": 0, "value": 0}'
Same as I2C.ReadRegB
, but read 2-byte (word) register value.
Same as I2C.WriteRegB
, but write 2-byte (word) register value.