Circuits.SPI (circuits_spi v1.0.0) View Source

This module enables Elixir programs to interact with hardware that's connected via a SPI bus.

Link to this section Summary

Types

SPI bus

SPI bus options. See open/2.

Functions

Return a list of available SPI bus names. If nothing is returned, it's possible that the kernel driver for that SPI bus is not enabled or the kernel's device tree is not configured. On Raspbian, run raspi-config and look in the advanced options.

Release any resources associated with the given file descriptor

Return info about the low level SPI interface

Open SPI channel On success, returns a reference. Use reference in subsequent calls to transfer SPI bus data

Perform a SPI transfer. The data should be a binary containing the bytes to send. Since SPI transfers simultaneously send and receive, the return value will be a binary of the same length or an error.

Link to this section Types

Specs

spi_bus() :: reference()

SPI bus

Call open/2 to obtain an SPI bus reference.

Specs

spi_option() ::
  {:mode, 0..3}
  | {:bits_per_word, 0..16}
  | {:speed_hz, pos_integer()}
  | {:delay_us, non_neg_integer()}

SPI bus options. See open/2.

Link to this section Functions

Specs

bus_names() :: [binary()]

Return a list of available SPI bus names. If nothing is returned, it's possible that the kernel driver for that SPI bus is not enabled or the kernel's device tree is not configured. On Raspbian, run raspi-config and look in the advanced options.

iex> Circuits.SPI.bus_names
["spidev0.0", "spidev0.1"]

Specs

close(spi_bus()) :: :ok

Release any resources associated with the given file descriptor

Specs

info() :: map()

Return info about the low level SPI interface

This may be helpful when debugging SPI issues.

Link to this function

open(bus_name, opts \\ [])

View Source

Specs

open(binary() | charlist(), [spi_option()]) :: {:ok, spi_bus()}

Open SPI channel On success, returns a reference. Use reference in subsequent calls to transfer SPI bus data

Parameters:

  • bus_name is the name of the bus (e.g., "spidev0.0")
  • opts is a keyword list to configure the bus

SPI bus options include:

  • mode: This specifies the clock polarity and phase to use. (0)
  • bits_per_word: bits per word on the bus (8)
  • speed_hz: bus speed (1000000)
  • delay_us: delay between transaction (10)

Specs

transfer(spi_bus(), binary()) :: {:ok, binary()} | {:error, term()}

Perform a SPI transfer. The data should be a binary containing the bytes to send. Since SPI transfers simultaneously send and receive, the return value will be a binary of the same length or an error.