SPI¶
The Serial Peripheral Interface bus (SPI) is a synchronous serial communication interface specification used for short distance communication, primarily for inter-chip communication within a single PCB.
SPI devices communicate in full duplex mode using a master-slave architecture with a single master.
MiraOS supports multiple independent instances. Only SPI master is supported currently.
Enums¶
mira_spi_mode_t¶
Value | Description |
---|---|
MIRA_SPI_MODE_0 | SPI mode 0. CPOL=0, CPHA=0. Clock idle low, sample data on leading clock edge. |
MIRA_SPI_MODE_1 | SPI mode 1. CPOL=0, CPHA=1. Clock idle low, sample data on trailing clock edge. |
MIRA_SPI_MODE_2 | SPI mode 2. CPOL=1, CPHA=0. Clock idle high, sample data on leading clock edge. |
MIRA_SPI_MODE_3 | SPI mode 3. CPOL=1, CPHA=1. Clock idle high, sample data on trailing clock edge. |
Structs¶
mira_spi_config_t¶
Type | Name | Description |
---|---|---|
uint32_t |
frequency | SPI clock frequency in Hz. The frequency will be set to the closest, lower or equal, supported frequency. |
mira_gpio_pin_t |
sck_pin | |
mira_gpio_pin_t |
mosi_pin | |
mira_gpio_pin_t |
miso_pin | |
mira_gpio_pin_t |
ss_pin | |
mira_spi_mode_t |
mode | |
mira_bit_order_t |
bit_order |
Functions¶
mira_spi_init¶
mira_status_t mira_spi_init( uint8_t spi_id, const mira_spi_config_t* config);
Before calling this function again mira_spi_uninit
has to be called.
Parameters
Parameter | Description |
---|---|
spi_id |
Peripheral id. |
config |
Configuration. Can be discarded after the return of this function. |
Return
See the enum definition.
Value | Description |
---|---|
MIRA_SUCCESS |
|
MIRA_ERROR_INVALID_ID |
|
MIRA_SPI_ERROR_CONFIG |
|
MIRA_SPI_ERROR_INIT |
mira_spi_uninit¶
mira_status_t mira_spi_uninit( uint8_t spi_id);
Parameters
Parameter | Description |
---|---|
spi_id |
Peripheral id. |
Return
Value | Description |
---|---|
MIRA_SUCCESS |
|
MIRA_ERROR_INVALID_ID |
mira_spi_transfer¶
mira_status_t mira_spi_transfer( uint8_t spi_id, uint8_t* tx_buffer, uint16_t tx_buffer_length, uint8_t* rx_buffer, uint16_t rx_buffer_length);
The process calling this function will be sent a PROCESS_EVENT_POLL
event after the transmission has completed.
Parameters
Parameter | Description |
---|---|
spi_id |
Peripheral id. |
tx_buffer |
Buffer containing the data to transmit. |
tx_buffer_length |
Number of bytes to transmit. |
rx_buffer |
Buffer where to store data received while transmitting. |
rx_buffer_length |
Max number of bytes to receive. |
Return
See the enum definition.
Value | Description |
---|---|
MIRA_SUCCESS |
|
MIRA_ERROR_INVALID_ID |
|
MIRA_ERROR_NOT_INITIALIZED |
|
MIRA_SPI_ERROR_BUSY |
|
MIRA_SPI_ERROR_BUFFER |
mira_spi_transfer_is_in_progress¶
mira_bool_t mira_spi_transfer_is_in_progress( uint8_t spi_id);
Parameters
Parameter | Description |
---|---|
spi_id |
Peripheral id. |
Return
An SPI transfer is in progress