Alcor6L/PicoLisp/i2c
Appearance
< Alcor6L
This module contains functions for accessing the I2C interfaces of the Alcor6L CPU.
Only master I2C mode is implemented in eLua (and Alcor6L).
Functions
[edit | edit source]i2c-setup
[edit | edit source]Setup the I2C interface.
(i2c-setup id speed)
- id - the ID of the I2C interface.
- speed - the clock frequency of the I2C interface. It can be *i2c-fast* (400KHz), *i2c-slow* (100KHz) or a number giving the required I2C bus clock speed in Hz.
Returns:
- speed - the actual speed of the I2C interface.
i2c-start
[edit | edit source]Send a START on the specified I2C interface.
(i2c-start id)
- id - the ID of the I2C interface.
Returns: NIL.
i2c-stop
[edit | edit source]Send a STOP on the specified I2C interface.
(i2c-stop id)
- id - the ID of the I2C interface.
Returns: NIL.
i2c-address
[edit | edit source]Send an address on the I2C interface.
(i2c-address id address direction)
- id - the ID of the I2C interface.
- address - the address.
- direction - *i2c.transmitter* if the master wants to send data, or *i2c-receiver* if the master wants to receive data.
Returns:
- asked - true if the address was acknowledged by an I2C slave, false otherwise.
i2c-write
[edit | edit source]Writes data to a slave that has already acknowledged an i2c-address call.
(i2c-write id any1 [any2] ... [anyn] )
- id - the ID of the I2C interface.
- any1 - the data to send. It can be either a number between 0 and 255, a symbol or a list.
- any2 (optional) - the second data to send.
- anyn (optional) - the n-th data to send.
Returns:
- wrote - the number of bytes actually written.
i2c-read
[edit | edit source](i2c-read id numbytes)
Reads a number of bytes from a slave that has already acknowledged an i2c-address call. It acknowledges all the bytes received except for the last one.
- id - the ID of the I2C interface.
- numbytes - the number of bytes to read.
Returns:
- data - a string with all the data read from the I2C interface.