Skip to main content

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​

ParameterTypeRangeDescription
<addr>hex0x00–0x7F7-bit I2C address (for example 0x48).
<reg>hex0x00–0xFFFirst register to read.
<len>decimal1–16Number of bytes to read.

Response​

I2C 0xAA 0xBB ...

The line starts with I2C followed by the bytes read, in hexadecimal.

Errors​

ReplyCondition
ERR I2C READ i2c_errorThe component did not acknowledge, or the transaction failed.
ERR I2C READ bad_argMissing 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)