Overview

This module contains functions for accessing the SPI interfaces of the eLua CPU.

IMPORTANT: right now, only master SPI mode is implemented in eLua.

Functions

clock = spi.setup( id, type, clock, cpol, cpha, databits )

Setup the SPI interface

Arguments:

  • id - the ID of the SPI interface.
  • type - SPI interface type, can be either spi.MASTER or spi.SLAVE. NOTE: currently, only master SPI mode is supported.
  • clock - the clock of the SPI interface.
  • cpol - the clock polarity (0 or 1).
  • cpha - the clock phase (0 or 1).
  • databits - the length of the SPI data word.

Returns: The actual clock set on the SPI interface. Depending on the hardware, this might have a different value than the clock parameter.

spi.sson( id )

Select the SS line (Slave Select) of the SPI interface. This is only applicable for SPI interfaces with a dedicated SS pin.

Arguments: id - the ID of the SPI interface.

Returns: nothing.

spi.ssoff( id )

Deselect the SS line (Slave Select) of the SPI interface. This is only applicable for SPI interfaces with a dedicated SS pin.

Arguments: id - the ID of the SPI interface.

Returns: nothing.

spi.write( id, data1, [data2], ..., [datan] )

Write one or more strings/numbers to the SPI interface.

Arguments:

  • id - the ID os the SPI interface.
  • data1 - the first string/number to send.
  • data2 (optional) - the second string/number to send.
  • datan (optional) - the n-th string/number to send.

Returns: nothing.

spi.readwrite( id, data1, [data2], ..., [datan] )

Write one or more strings/numbers to the SPI interface and return the data read from the same interface.

Arguments:

  • id - the ID os the SPI interface.
  • data1 - the first string/number to send.
  • data2 (optional) - the second string/number to send.
  • datan (optional) - the n-th string/number to send.

Returns: An array with all the data read from the SPI interface.