I2C READ
Syntax
I2C READ <addr> <reg> <len>
Description
Reads len bytes starting at a register of an I2C component. Addresses and register are hexadecimal. I2C transactions can add noise to the data of a running acquisition; prefer to read while acquisition is stopped.
Parameters
| Parameter | Type | Range | Description |
|---|---|---|---|
<addr> | hex | 0x00–0x7F | 7-bit I2C address (for example 0x48). |
<reg> | hex | 0x00–0xFF | First register to read. |
<len> | decimal | 1–16 | Number of bytes to read. |
Response
I2C 0xAA 0xBB ...
The line starts with I2C followed by the bytes read, in hexadecimal.
Errors
| Reply | Condition |
|---|---|
ERR I2C READ i2c_error | The component did not acknowledge, or the transaction failed. |
ERR I2C READ bad_arg | Missing or malformed arguments, address out of range, or len outside 1–16. |
Example
Read 4 bytes from register 0x00 of the component at address 0x48:
i2c_read.py
from hmcls_udp import Board
board = Board("192.168.1.11")
line = board.query("I2C READ 0x48 0x00 4")[0]
values = [int(v, 16) for v in line.split()[1:]]
print(values)