API Reference
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_spi.c File Reference

Serial peripheral interface controller (SPI) HW driver source file. More...

#include <neorv32.h>

Functions

int neorv32_spi_available (void)
void neorv32_spi_setup (int prsc, int cdiv, int clk_phase, int clk_polarity)
uint32_t neorv32_spi_clock_speed (void)
int neorv32_spi_fifo_depth (void)
void neorv32_spi_cs_en (int cs)
void neorv32_spi_cs_dis (void)
uint8_t neorv32_spi_transfer (uint8_t data)
void neorv32_spi_send (uint8_t data)
int neorv32_spi_rx_avail (void)
int neorv32_spi_tx_empty (void)
int neorv32_spi_tx_full (void)
int neorv32_spi_busy (void)

Detailed Description

Serial peripheral interface controller (SPI) HW driver source file.

Function Documentation

◆ neorv32_spi_available()

int neorv32_spi_available ( void )

Check if SPI unit was synthesized.

Returns
0 if SPI was not synthesized, non-zero if SPI is available.

◆ neorv32_spi_busy()

int neorv32_spi_busy ( void )

Check if SPI transceiver is busy or TX FIFO not empty.

Returns
0 if idle, non-zero if busy

◆ neorv32_spi_clock_speed()

uint32_t neorv32_spi_clock_speed ( void )

Get configured clock speed in Hz.

Returns
Actual configured SPI clock speed in Hz.

◆ neorv32_spi_cs_dis()

void neorv32_spi_cs_dis ( void )

Deactivate currently active SPI chip select signal.

Note
The SPI chip select output lines are HIGH when deactivated.
This function is blocking.

◆ neorv32_spi_cs_en()

void neorv32_spi_cs_en ( int cs)

Activate single SPI chip select signal.

Note
This function is blocking.
Parameters
csChip select line to activate (0..7).

◆ neorv32_spi_fifo_depth()

int neorv32_spi_fifo_depth ( void )

Get SPI FIFO depth.

Returns
FIFO depth (number of entries).

◆ neorv32_spi_rx_avail()

int neorv32_spi_rx_avail ( void )

Check if RX FIFO data is available.

Returns
Zero if no data available, non-zero if RX FIFO data is available.

◆ neorv32_spi_send()

void neorv32_spi_send ( uint8_t data)

Send byte via SPI and discard received data.

Note
This function is blocking.
Parameters
dataTransmit data (8-bit, LSB-aligned).

◆ neorv32_spi_setup()

void neorv32_spi_setup ( int prsc,
int cdiv,
int clk_phase,
int clk_polarity )

Enable and configure SPI controller. The SPI control register bits are listed in NEORV32_SPI_CTRL_enum.

Parameters
[in]prscClock prescaler select (0..7). See NEORV32_CLOCK_PRSC_enum.
[in]cdivClock divider (0..15).
[in]clk_phaseClock phase (0=sample on rising edge, 1=sample on falling edge).
[in]clk_polarityClock polarity (when idle).

◆ neorv32_spi_transfer()

uint8_t neorv32_spi_transfer ( uint8_t data)

Perform a single SPI data transfer (send a byte while receiving a byte).

Note
This function is blocking.
Parameters
tx_dataTransmit data (8-bit, LSB-aligned).
Returns
Receive data (8-bit, LSB-aligned).

◆ neorv32_spi_tx_empty()

int neorv32_spi_tx_empty ( void )

Check if TX FIFO is empty.

Returns
Zero if RX FIFO is not empty, non-zero if RX FIFO is empty.

◆ neorv32_spi_tx_full()

int neorv32_spi_tx_full ( void )

Check if TX FIFO is full.

Returns
Zero if TX FIFO is not full, non-zero if TX FIFO is full.