Circuits.SPI (circuits_spi v1.1.0) View Source
This module enables Elixir programs to interact with hardware that's connected via a SPI bus.
Link to this section Summary
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
Return the maximum transfer size in bytes
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.
Specs
max_transfer_size() :: non_neg_integer()
Return the maximum transfer size in bytes
The number of bytes that can be sent and received at a time
may be capped by the low level SPI interface. For example,
the Linux spidev
driver allocates its transfer buffer at
initialization based on the bufsiz
parameter and rejects
requests that won't fit.
If you're sending large amounts of data over SPI, use this function to determine how to split up large messages.
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
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.