SPI
API Reference
How To Setup SPI
yoctoOutofTreeKernelModule
Overview
This API is used by apps to control a Serial Peripheral Interface (SPI).
The SPI API is configured as a four wire interface:
- Clock - Serial Clock
- MOSI - Master Output
- MISO - Master Input
- SS or CS - Chip select
Usage
The sample code in this section shows how to use the SPI API for a user space app.
Handle for passing to related functions to access the SPI device:
le_spi_DeviceHandleRef_t spiHandle;
le_spi_Open() opens the spi
file handle:
le_result_t res;res = le_spi_Open("spidev0.0", &spiHandle);
le_spi_Configure() initializes all the parameters on the master side based on the implementation below uses mode = 0, 8 bit data, 960kbps and MSB first:
le_spi_Configure(spiHandle, 0, 8, 960000, 0);
le_spi_WriteHD() writes data to slave device in half-duplex mode: write_buffer_tx is an array. Example defined below:
uinti8_t write_buffer_tx[] ={0xC7, 0x94, 0x80, 0x9A};le_result_t res;res = le_spi_WriteHD(spiHandle, write_buffer_tx, NUM_ARRAY_MEMBERS(write_buffer_tx));
le_spi_WriteReadHD() writes and reads to/from slave device in half-duplex mode:
le_result_t res;le_spi_WriteReadHD(spiHandle, read_ID_tx, NUM_ARRAY_MEMBERS(read_ID_tx), ID_rx,&readBufferSize);
read_ID_tx is an array that is transmitted to the device. ID_rx is a buffer reserved for data received from the device.
le_spi_WriteReadFD() writes and reads to/from slave in full-duplex mode:
le_result_t res;res = le_spi_WriteReadHD(spiHandle, read_buffer_tx, read_rx, NUM_ARRAY_MEMBERS(read_buffer_tx);
read_buffer_tx is an array transmitted to the device. read_rx is a buffer reserved for data received from the device. Buffer size for tx and rx must be the same.
le_spi_Close() closes the spi handle:
le_spi_Close(spiHandle);
Copyright (C) Sierra Wireless Inc.