en fr

Sysquake Pro – Table of Contents

Sysquake – Table of Contents

Sysquake for LaTeX – Table of Contents

Extension - I2C

This section describes functions which read and write to an I2C bus. Currently, these functions are available only on Linux computers.

Functions

i2copen

Open an I2C bus.

Syntax

id = i2copen
id = i2copen(path)

Description

Without input argument, i2copen opens the first I2C bus (/dev/i2c/0 on Linux). It returns a number which must be used with all the other I2C functions.

i2copen(path) opens the I2C bus associated with the specified device path, such as /dev/i2c/1.

See also

i2cclose, i2cread, i2cwrite

i2cclose

Close an I2C bus.

Syntax

i2cclose(id)

Description

i2cclose(id) closes the I2C bus which has been opened with i2copen. Its argument must be the number returned by i2copen. I2C busses left open are closed automatically when LME is terminated.

See also

i2copen

i2cread

Read a word from an I2C bus.

Syntax

value = i2cread(id, slaveaddr, regaddr)
value = i2cread(id, slaveaddr, regaddr, precision)

Description

i2cread(id,slaveaddr,regaddr) reads the 8-bit register regaddr of device slaveaddr on the I2C bus identified by id. The result is of type uint8.

i2cread(id,slaveaddr,regaddr,precision) reads a register whose size, signedness and endianness is specified in string precision. The following values are accepted:

PrecisionMeaning
int8signed 8-bit integer (-128 <= x <= 127)
int16signed 16-bit integer (-32768 <= x <= 32767)
int32signed 32-bit integer (-2147483648 <= x <= 2147483647)
uint8unsigned 8-bit integer (0 <= x <= 255)
uint16unsigned 16-bit integer (0 <= x <= 65535)
uint32unsigned 32-bit integer (0 <= x <= 4294967295)

By default, multibyte words are encoded with the least significant byte first (little endian). The characters ';b' can be appended to specify that they are encoded with the most significant byte first (big endian) (for symmetry, ';l' is accepted and ignored).

Example

id = i2copen;
version = i2cread(id, 0x62, 0x00);
position = i2cread(id, 0x62, 0x10, 'uint32');
speed = i2cread(id, 0x62, 0x20, 'int16');
i2cclose(id);

See also

i2copen, i2cwrite

i2cwrite

Write a word to an I2C bus.

Syntax

i2cwrite(id, slaveaddr, regaddr, value)
i2cwrite(id, slaveaddr, regaddr, value, precision)

Description

i2cwrite(id,slaveaddr,regaddr,value) writes the 8-bit word value to the register regaddr of device slaveaddr on the I2C bus identified by id. value is converted to an 8-bit integer if necessary.

i2cwrite(id,slaveaddr,regaddr,value,precision) writes the word value with size and endianness specified in string precision. See i2cread for a list of supported values. Signedness is irrelevant and ignored.

See also

i2copen, i2cread