Astra MCU SDK Peripheral Driver Library
 
Loading...
Searching...
No Matches

Topics

 Enumerated Types
 Enumerated types for SPI driver.
 
 Data Structures
 Data structures for SPI driver.
 
 Functions
 

Detailed Description

Driver API for Synaptics SPI peripheral.

The SPI (Serial Peripheral Interface) protocol is a synchronous serial communication protocol that supports full-duplex or half-duplex data exchange between a controller and one or more peripherals.

Features:

Note
SPI APIs are divided into two categories:
Warning
Mixing high-level and low-level SPI APIs for the same instance is not recommended. Each has different expectations for FIFO management and interrupt handling. Use only one model per instance to avoid undefined behavior.

Configuration Considerations

To initialize and use the SPI driver:

spi_init

Initialize the SPI hardware and internal driver structures for the specified SPI instance.

spi_deinit

Deinitializes the SPI hardware and releases any resources held by the driver for the specified SPI instance.

spi_set_config

Sets the SPI hardware configuration for the specified SPI instance, including FRF, NDF, Clk polarity, phase and baud rate. Programs the SPI registers accordingly and stores the baud rate achieved.

spi_config_t spi_cfg_controller = {
.spi_controller = true,
.clock_mode = SPI_CPHA0_CPOL0,
.xfer_mode = SPI_TRANSMIT_ONLY,
.frame_size = SPI_FRAME_SIZE,
.toggle_peripheral_select = true,
.disable_peripheral_out = false,
.num_rx_frames = SPI_TRANSFER_LENGTH,
.spi_clk_freq_khz = SPI_CLOCK_FREQ,
.rx_sample_delay = 0,
};
uint32_t actual_clk = 0;
if (spi_set_configuration(SPI_C, &spi_cfg_controller, &actual_clk) != 0) {
return SPI_ERROR;
}

Controller PINMUX Configuration for SPI

pinmux_set_pin_func(SPI_MSTR_MISO, SPI_MSTR_MISO__SPI_MSTR_MISO);
pinmux_set_pin_func(SPI_MSTR_MOSI, SPI_MSTR_MOSI__SPI_MSTR_MOSI);
pinmux_set_pin_func(SPI_MSTR_CLK, SPI_MSTR_CLK__SPI_MSTR_CLK);
pinmux_set_pin_func(SPI_MSTR_CS, SPI_MSTR_CS__SPI_MSTR_CS);

Peripheral PINMUX Configuration for SPI

pinmux_set_pin_func(SPI_SLV_MISO, SPI_SLV_MISO__SPI_SLV_MISO);
pinmux_set_pin_func(SPI_SLV_MOSI, SPI_SLV_MOSI__SPI_SLV_MOSI);
pinmux_set_pin_func(SPI_SLV_CLK, SPI_SLV_CLK__SPI_SLV_CLK);
pinmux_set_pin_func(SPI_SLV_CS, SPI_SLV_CS__SPI_SLV_CS);

High-level Functions.

spi_transfer_non_blocking

Initiates a non-blocking transmit operation over SPI for the specified instance. Data is written to the SPI transmit FIFO and the function returns immediately. Completion is handled via callback.

.tx_buff = tx_buffer,
.rx_buff = rx_buffer,
.xfer_size = transfer_size,
.tx_dummy = 0xFF,
.callback = spi_callback_handler,
};

Low-level Functions.

spi_write_tx_data

Writes a single word to the SPI transmit FIFO. Should be used only when FIFO has available space. Non-blocking; does not wait for transmission to complete.

int data = 0xA5;