libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
SPI peripheral API
Collaboration diagram for SPI peripheral API:

Functions

void spi_enable (uint32_t spi)
 SPI Enable. More...
 
void spi_disable (uint32_t spi)
 SPI Disable. More...
 
uint16_t spi_clean_disable (uint32_t spi)
 SPI Clean Disable. More...
 
void spi_write (uint32_t spi, uint16_t data)
 SPI Data Write. More...
 
void spi_send (uint32_t spi, uint16_t data)
 SPI Data Write with Blocking. More...
 
uint16_t spi_read (uint32_t spi)
 SPI Data Read. More...
 
uint16_t spi_xfer (uint32_t spi, uint16_t data)
 SPI Data Write and Read Exchange. More...
 
void spi_set_bidirectional_mode (uint32_t spi)
 SPI Set Bidirectional Simplex Mode. More...
 
void spi_set_unidirectional_mode (uint32_t spi)
 SPI Set Unidirectional Mode. More...
 
void spi_set_bidirectional_receive_only_mode (uint32_t spi)
 SPI Set Bidirectional Simplex Receive Only Mode. More...
 
void spi_set_bidirectional_transmit_only_mode (uint32_t spi)
 SPI Set Bidirectional Simplex Receive Only Mode. More...
 
void spi_enable_crc (uint32_t spi)
 SPI Enable the CRC. More...
 
void spi_disable_crc (uint32_t spi)
 SPI Disable the CRC. More...
 
void spi_set_next_tx_from_buffer (uint32_t spi)
 SPI Next Transmit is a Data Word. More...
 
void spi_set_next_tx_from_crc (uint32_t spi)
 SPI Next Transmit is a CRC Word. More...
 
void spi_set_full_duplex_mode (uint32_t spi)
 SPI Set Full Duplex (3-wire) Mode. More...
 
void spi_set_receive_only_mode (uint32_t spi)
 SPI Set Receive Only Mode for Simplex (2-wire) Unidirectional Transfers. More...
 
void spi_disable_software_slave_management (uint32_t spi)
 SPI Disable Slave Management by Hardware. More...
 
void spi_enable_software_slave_management (uint32_t spi)
 SPI Enable Slave Management by Software. More...
 
void spi_set_nss_high (uint32_t spi)
 SPI Set the Software NSS Signal High. More...
 
void spi_set_nss_low (uint32_t spi)
 SPI Set the Software NSS Signal Low. More...
 
void spi_send_lsb_first (uint32_t spi)
 SPI Set to Send LSB First. More...
 
void spi_send_msb_first (uint32_t spi)
 SPI Set to Send MSB First. More...
 
void spi_set_baudrate_prescaler (uint32_t spi, uint8_t baudrate)
 SPI Set the Baudrate Prescaler. More...
 
void spi_set_master_mode (uint32_t spi)
 SPI Set to Master Mode. More...
 
void spi_set_slave_mode (uint32_t spi)
 SPI Set to Slave Mode. More...
 
void spi_set_clock_polarity_1 (uint32_t spi)
 SPI Set the Clock Polarity to High when Idle. More...
 
void spi_set_clock_polarity_0 (uint32_t spi)
 SPI Set the Clock Polarity to Low when Idle. More...
 
void spi_set_clock_phase_1 (uint32_t spi)
 SPI Set the Clock Phase to Capture on Trailing Edge. More...
 
void spi_set_clock_phase_0 (uint32_t spi)
 SPI Set the Clock Phase to Capture on Leading Edge. More...
 
void spi_enable_tx_buffer_empty_interrupt (uint32_t spi)
 SPI Enable the Transmit Buffer Empty Interrupt. More...
 
void spi_disable_tx_buffer_empty_interrupt (uint32_t spi)
 SPI Disable the Transmit Buffer Empty Interrupt. More...
 
void spi_enable_rx_buffer_not_empty_interrupt (uint32_t spi)
 SPI Enable the Receive Buffer Ready Interrupt. More...
 
void spi_disable_rx_buffer_not_empty_interrupt (uint32_t spi)
 SPI Disable the Receive Buffer Ready Interrupt. More...
 
void spi_enable_error_interrupt (uint32_t spi)
 SPI Enable the Error Interrupt. More...
 
void spi_disable_error_interrupt (uint32_t spi)
 SPI Disable the Error Interrupt. More...
 
void spi_enable_ss_output (uint32_t spi)
 SPI Set the NSS Pin as an Output. More...
 
void spi_disable_ss_output (uint32_t spi)
 SPI Set the NSS Pin as an Input. More...
 
void spi_enable_tx_dma (uint32_t spi)
 SPI Enable Transmit Transfers via DMA. More...
 
void spi_disable_tx_dma (uint32_t spi)
 SPI Disable Transmit Transfers via DMA. More...
 
void spi_enable_rx_dma (uint32_t spi)
 SPI Enable Receive Transfers via DMA. More...
 
void spi_disable_rx_dma (uint32_t spi)
 SPI Disable Receive Transfers via DMA. More...
 
void spi_set_standard_mode (uint32_t spi, uint8_t mode)
 SPI Standard Mode selection. More...
 
int spi_init_master (uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha, uint32_t lsbfirst)
 Configure the SPI as Master. More...
 
void spi_send8 (uint32_t spi, uint8_t data)
 
uint8_t spi_read8 (uint32_t spi)
 
void spi_set_crcl_8bit (uint32_t spi)
 SPI Set CRC length to 8 bits. More...
 
void spi_set_crcl_16bit (uint32_t spi)
 SPI Set CRC length to 16 bits. More...
 
void spi_set_data_size (uint32_t spi, uint16_t data_s)
 SPI Set data size. More...
 
void spi_fifo_reception_threshold_8bit (uint32_t spi)
 SPI Set reception threshold to 8 bits. More...
 
void spi_fifo_reception_threshold_16bit (uint32_t spi)
 SPI Set reception threshold to 16 bits. More...
 

Detailed Description

Author
© 2009 Uwe Hermann uwe@h.nosp@m.erma.nosp@m.nn-uw.nosp@m.e.de
© 2012 Ken Sarkies ksark.nosp@m.ies@.nosp@m.inter.nosp@m.node.nosp@m..on.n.nosp@m.et

Devices can have up to three SPI peripherals. The common 4-wire full-duplex mode of operation is supported, along with 3-wire variants using unidirectional communication modes or half-duplex bidirectional communication. A variety of options allows many of the SPI variants to be supported. Multimaster operation is also supported. A CRC can be generated and checked in hardware.

Note
Some JTAG pins need to be remapped if SPI is to be used.
The I2S protocol shares the SPI hardware so the two protocols cannot be used at the same time on the same peripheral.

Example: Clk/4, positive clock polarity, leading edge trigger, 8-bit words, LSB first.

spi_write(SPI1, 0x55); // 8-bit write
spi_write(SPI1, 0xaa88); // 16-bit write
reg8 = spi_read(SPI1); // 8-bit read
reg16 = spi_read(SPI1); // 16-bit read
#define SPI_CR1_BAUDRATE_FPCLK_DIV_4
#define SPI_CR1_CPHA_CLK_TRANSITION_1
#define SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE
uint16_t spi_read(uint32_t spi)
SPI Data Read.
int spi_init_master(uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha, uint32_t lsbfirst)
Configure the SPI as Master.
Definition: spi_common_v2.c:76
void spi_write(uint32_t spi, uint16_t data)
SPI Data Write.
#define SPI_CR1_LSBFIRST
#define SPI1
Author
© 2009 Uwe Hermann uwe@h.nosp@m.erma.nosp@m.nn-uw.nosp@m.e.de
© 2012 Ken Sarkies ksark.nosp@m.ies@.nosp@m.inter.nosp@m.node.nosp@m..on.n.nosp@m.et

Devices can have up to three SPI peripherals. The common 4-wire full-duplex mode of operation is supported, along with 3-wire variants using unidirectional communication modes or half-duplex bidirectional communication. A variety of options allows many of the SPI variants to be supported. Multimaster operation is also supported. A CRC can be generated and checked in hardware.

Note
Some JTAG pins need to be remapped if SPI is to be used.
The I2S protocol shares the SPI hardware so the two protocols cannot be used at the same time on the same peripheral.

Example: Clk/4, positive clock polarity, leading edge trigger, 8-bit words, LSB first.

spi_write(SPI1, 0x55); // 8-bit write
spi_write(SPI1, 0xaa88); // 16-bit write
reg8 = spi_read(SPI1); // 8-bit read
reg16 = spi_read(SPI1); // 16-bit read
#define SPI_CR1_CRCL_8BIT
Definition: spi_common_v2.h:46

Function Documentation

◆ spi_clean_disable()

uint16_t spi_clean_disable ( uint32_t  spi)

SPI Clean Disable.

Disable the SPI peripheral according to the procedure in section 23.3.8 of the reference manual. This prevents corruption of any ongoing transfers and prevents the BSY flag from becoming unreliable.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
Returns
data Unsigned int16. 8 or 16 bit data from final read.

Definition at line 104 of file spi_common_all.c.

References SPI_CR1, SPI_DR, SPI_SR, SPI_SR_BSY, SPI_SR_RXNE, and SPI_SR_TXE.

◆ spi_disable()

void spi_disable ( uint32_t  spi)

SPI Disable.

The SPI peripheral is disabled.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 84 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_SPE.

◆ spi_disable_crc()

void spi_disable_crc ( uint32_t  spi)

SPI Disable the CRC.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 276 of file spi_common_all.c.

References SPI_CR1.

◆ spi_disable_error_interrupt()

void spi_disable_error_interrupt ( uint32_t  spi)

SPI Disable the Error Interrupt.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 570 of file spi_common_all.c.

References SPI_CR2.

◆ spi_disable_rx_buffer_not_empty_interrupt()

void spi_disable_rx_buffer_not_empty_interrupt ( uint32_t  spi)

SPI Disable the Receive Buffer Ready Interrupt.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 548 of file spi_common_all.c.

References SPI_CR2.

◆ spi_disable_rx_dma()

void spi_disable_rx_dma ( uint32_t  spi)

SPI Disable Receive Transfers via DMA.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 651 of file spi_common_all.c.

References SPI_CR2.

◆ spi_disable_software_slave_management()

void spi_disable_software_slave_management ( uint32_t  spi)

SPI Disable Slave Management by Hardware.

In slave mode the NSS hardware input is used as a select enable for the slave.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 342 of file spi_common_all.c.

References SPI_CR1.

◆ spi_disable_ss_output()

void spi_disable_ss_output ( uint32_t  spi)

SPI Set the NSS Pin as an Input.

In master mode this allows the master to sense the presence of other masters. If NSS is then pulled low the master is placed into slave mode. In slave mode NSS becomes a slave enable.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 599 of file spi_common_all.c.

References SPI_CR2.

◆ spi_disable_tx_buffer_empty_interrupt()

void spi_disable_tx_buffer_empty_interrupt ( uint32_t  spi)

SPI Disable the Transmit Buffer Empty Interrupt.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 526 of file spi_common_all.c.

References SPI_CR2.

◆ spi_disable_tx_dma()

void spi_disable_tx_dma ( uint32_t  spi)

SPI Disable Transmit Transfers via DMA.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 625 of file spi_common_all.c.

References SPI_CR2.

◆ spi_enable()

void spi_enable ( uint32_t  spi)

SPI Enable.

The SPI peripheral is enabled.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 70 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_SPE.

◆ spi_enable_crc()

void spi_enable_crc ( uint32_t  spi)

SPI Enable the CRC.

The SPI peripheral is set to use a CRC field for transmit and receive.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 265 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_CRCEN.

◆ spi_enable_error_interrupt()

void spi_enable_error_interrupt ( uint32_t  spi)

SPI Enable the Error Interrupt.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 559 of file spi_common_all.c.

References SPI_CR2, and SPI_CR2_ERRIE.

◆ spi_enable_rx_buffer_not_empty_interrupt()

void spi_enable_rx_buffer_not_empty_interrupt ( uint32_t  spi)

SPI Enable the Receive Buffer Ready Interrupt.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 537 of file spi_common_all.c.

References SPI_CR2, and SPI_CR2_RXNEIE.

◆ spi_enable_rx_dma()

void spi_enable_rx_dma ( uint32_t  spi)

SPI Enable Receive Transfers via DMA.

This allows received data streams to proceed unattended using DMA to move data from the receive buffer as data becomes available. The DMA channels provided for each SPI peripheral are given in the Technical Manual DMA section.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 640 of file spi_common_all.c.

References SPI_CR2, and SPI_CR2_RXDMAEN.

◆ spi_enable_software_slave_management()

void spi_enable_software_slave_management ( uint32_t  spi)

SPI Enable Slave Management by Software.

In slave mode the NSS hardware input is replaced by an internal software enable/disable of the slave (spi_set_nss_high).

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 356 of file spi_common_all.c.

References SPI_CR1, SPI_CR1_SSM, and SPI_CR2.

◆ spi_enable_ss_output()

void spi_enable_ss_output ( uint32_t  spi)

SPI Set the NSS Pin as an Output.

Normally used in master mode to allows the master to place all devices on the SPI bus into slave mode. Multimaster mode is not possible.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 584 of file spi_common_all.c.

References SPI_CR2, and SPI_CR2_SSOE.

◆ spi_enable_tx_buffer_empty_interrupt()

void spi_enable_tx_buffer_empty_interrupt ( uint32_t  spi)

SPI Enable the Transmit Buffer Empty Interrupt.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 515 of file spi_common_all.c.

References SPI_CR2, and SPI_CR2_TXEIE.

◆ spi_enable_tx_dma()

void spi_enable_tx_dma ( uint32_t  spi)

SPI Enable Transmit Transfers via DMA.

This allows transmissions to proceed unattended using DMA to move data to the transmit buffer as it becomes available. The DMA channels provided for each SPI peripheral are given in the Technical Manual DMA section.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 614 of file spi_common_all.c.

References SPI_CR2, and SPI_CR2_TXDMAEN.

◆ spi_fifo_reception_threshold_16bit()

void spi_fifo_reception_threshold_16bit ( uint32_t  spi)

SPI Set reception threshold to 16 bits.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 164 of file spi_common_v2.c.

References SPI_CR2.

◆ spi_fifo_reception_threshold_8bit()

void spi_fifo_reception_threshold_8bit ( uint32_t  spi)

SPI Set reception threshold to 8 bits.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 153 of file spi_common_v2.c.

References SPI_CR2, and SPI_CR2_FRXTH.

◆ spi_init_master()

int spi_init_master ( uint32_t  spi,
uint32_t  br,
uint32_t  cpol,
uint32_t  cpha,
uint32_t  lsbfirst 
)

Configure the SPI as Master.

The SPI peripheral is configured as a master with communication parameters baudrate, frame format lsb/msb first, clock polarity and phase. The SPI enable, CRC enable, CRC next CRC length controls are not affected. These must be controlled separately.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]brUnsigned int32. Baudrate SPI peripheral baud rates.
[in]cpolUnsigned int32. Clock polarity SPI clock polarity.
[in]cphaUnsigned int32. Clock Phase SPI clock phase.
[in]lsbfirstUnsigned int32. Frame format lsb/msb first SPI lsb/msb first.
Returns
int. Error code.

Definition at line 76 of file spi_common_v2.c.

References SPI_CR1, SPI_CR1_CRCEN, SPI_CR1_CRCL, SPI_CR1_CRCNEXT, SPI_CR1_MSTR, SPI_CR1_SPE, SPI_CR2, and SPI_CR2_SSOE.

◆ spi_read()

uint16_t spi_read ( uint32_t  spi)

SPI Data Read.

Data is read from the SPI interface after the incoming transfer has finished.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
Returns
data Unsigned int16. 8 or 16 bit data.

Definition at line 165 of file spi_common_all.c.

References SPI_DR, SPI_SR, and SPI_SR_RXNE.

◆ spi_read8()

uint8_t spi_read8 ( uint32_t  spi)

Definition at line 105 of file spi_common_v2.c.

References SPI_DR8, SPI_SR, and SPI_SR_RXNE.

◆ spi_send()

void spi_send ( uint32_t  spi,
uint16_t  data 
)

SPI Data Write with Blocking.

Data is written to the SPI interface after the previous write transfer has finished.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]dataUnsigned int16. 8 or 16 bit data to be written.

Definition at line 147 of file spi_common_all.c.

References SPI_DR, SPI_SR, and SPI_SR_TXE.

◆ spi_send8()

void spi_send8 ( uint32_t  spi,
uint8_t  data 
)

Definition at line 97 of file spi_common_v2.c.

References SPI_DR8, SPI_SR, and SPI_SR_TXE.

◆ spi_send_lsb_first()

void spi_send_lsb_first ( uint32_t  spi)

SPI Set to Send LSB First.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 400 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_LSBFIRST.

◆ spi_send_msb_first()

void spi_send_msb_first ( uint32_t  spi)

SPI Set to Send MSB First.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 411 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_baudrate_prescaler()

void spi_set_baudrate_prescaler ( uint32_t  spi,
uint8_t  baudrate 
)

SPI Set the Baudrate Prescaler.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]baudrateUnsigned int8. Baudrate prescale value SPI peripheral baud rate prescale values.

Definition at line 426 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_bidirectional_mode()

void spi_set_bidirectional_mode ( uint32_t  spi)

SPI Set Bidirectional Simplex Mode.

The SPI peripheral is set for bidirectional transfers in two-wire simplex mode (using a clock wire and a bidirectional data wire).

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 205 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_BIDIMODE.

◆ spi_set_bidirectional_receive_only_mode()

void spi_set_bidirectional_receive_only_mode ( uint32_t  spi)

SPI Set Bidirectional Simplex Receive Only Mode.

The SPI peripheral is set for bidirectional transfers in two-wire simplex mode (using a clock wire and a bidirectional data wire), and is placed in a receive state.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 235 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_BIDIMODE.

◆ spi_set_bidirectional_transmit_only_mode()

void spi_set_bidirectional_transmit_only_mode ( uint32_t  spi)

SPI Set Bidirectional Simplex Receive Only Mode.

The SPI peripheral is set for bidirectional transfers in two-wire simplex mode (using a clock wire and a bidirectional data wire), and is placed in a transmit state.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 251 of file spi_common_all.c.

References SPI_CR1, SPI_CR1_BIDIMODE, and SPI_CR1_BIDIOE.

◆ spi_set_clock_phase_0()

void spi_set_clock_phase_0 ( uint32_t  spi)

SPI Set the Clock Phase to Capture on Leading Edge.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
See also
spi_set_clock_phase_1

Definition at line 504 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_clock_phase_1()

void spi_set_clock_phase_1 ( uint32_t  spi)

SPI Set the Clock Phase to Capture on Trailing Edge.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
See also
spi_set_clock_phase_0

Definition at line 492 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_CPHA.

◆ spi_set_clock_polarity_0()

void spi_set_clock_polarity_0 ( uint32_t  spi)

SPI Set the Clock Polarity to Low when Idle.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
See also
spi_set_clock_polarity_1

Definition at line 480 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_clock_polarity_1()

void spi_set_clock_polarity_1 ( uint32_t  spi)

SPI Set the Clock Polarity to High when Idle.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
See also
spi_set_clock_polarity_0

Definition at line 468 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_CPOL.

◆ spi_set_crcl_16bit()

void spi_set_crcl_16bit ( uint32_t  spi)

SPI Set CRC length to 16 bits.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 130 of file spi_common_v2.c.

References SPI_CR1, and SPI_CR1_CRCL.

◆ spi_set_crcl_8bit()

void spi_set_crcl_8bit ( uint32_t  spi)

SPI Set CRC length to 8 bits.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 119 of file spi_common_v2.c.

References SPI_CR1.

◆ spi_set_data_size()

void spi_set_data_size ( uint32_t  spi,
uint16_t  data_s 
)

SPI Set data size.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]data_sUnsigned int16. data size SPI data size.

Definition at line 141 of file spi_common_v2.c.

References SPI_CR2, and SPI_CR2_DS_MASK.

◆ spi_set_full_duplex_mode()

void spi_set_full_duplex_mode ( uint32_t  spi)

SPI Set Full Duplex (3-wire) Mode.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 317 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_master_mode()

void spi_set_master_mode ( uint32_t  spi)

SPI Set to Master Mode.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 445 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_MSTR.

◆ spi_set_next_tx_from_buffer()

void spi_set_next_tx_from_buffer ( uint32_t  spi)

SPI Next Transmit is a Data Word.

The next transmission to take place is a data word from the transmit buffer. This must be called before transmission to distinguish between sending of a data or CRC word.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 291 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_next_tx_from_crc()

void spi_set_next_tx_from_crc ( uint32_t  spi)

SPI Next Transmit is a CRC Word.

The next transmission to take place is a crc word from the hardware crc unit. This must be called before transmission to distinguish between sending of a data or CRC word.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 306 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_CRCNEXT.

◆ spi_set_nss_high()

void spi_set_nss_high ( uint32_t  spi)

SPI Set the Software NSS Signal High.

In slave mode, and only when software slave management is used, this replaces the NSS signal with a slave select enable signal.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 375 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_SSI.

◆ spi_set_nss_low()

void spi_set_nss_low ( uint32_t  spi)

SPI Set the Software NSS Signal Low.

In slave mode, and only when software slave management is used, this replaces the NSS signal with a slave select disable signal.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 389 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_receive_only_mode()

void spi_set_receive_only_mode ( uint32_t  spi)

SPI Set Receive Only Mode for Simplex (2-wire) Unidirectional Transfers.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 329 of file spi_common_all.c.

References SPI_CR1, and SPI_CR1_RXONLY.

◆ spi_set_slave_mode()

void spi_set_slave_mode ( uint32_t  spi)

SPI Set to Slave Mode.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 456 of file spi_common_all.c.

References SPI_CR1.

◆ spi_set_standard_mode()

void spi_set_standard_mode ( uint32_t  spi,
uint8_t  mode 
)

SPI Standard Mode selection.

Set SPI standard Modes

Mode CPOL CPHA
0 0 0
1 0 1
2 1 0
3 1 1
Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]modeUnsigned int8. Standard SPI mode (0, 1, 2, 3)
See also
spi_set_clock_phase_0 spi_set_clock_phase_1
spi_set_clock_polarity_0 spi_set_clock_polarity_1

Definition at line 671 of file spi_common_all.c.

References SPI_CR1, SPI_CR1_CPHA, and SPI_CR1_CPOL.

◆ spi_set_unidirectional_mode()

void spi_set_unidirectional_mode ( uint32_t  spi)

SPI Set Unidirectional Mode.

The SPI peripheral is set for unidirectional transfers. This is used in full duplex mode or when the SPI is placed in two-wire simplex mode that uses a clock wire and a unidirectional data wire.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.

Definition at line 220 of file spi_common_all.c.

References SPI_CR1.

◆ spi_write()

void spi_write ( uint32_t  spi,
uint16_t  data 
)

SPI Data Write.

Data is written to the SPI interface.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]dataUnsigned int16. 8 or 16 bit data to be written.

Definition at line 131 of file spi_common_all.c.

References SPI_DR.

Referenced by spi_xfer().

Here is the caller graph for this function:

◆ spi_xfer()

uint16_t spi_xfer ( uint32_t  spi,
uint16_t  data 
)

SPI Data Write and Read Exchange.

Data is written to the SPI interface, then a read is done after the incoming transfer has finished.

Parameters
[in]spiUnsigned int32. SPI peripheral identifier SPI Register base address.
[in]dataUnsigned int16. 8 or 16 bit data to be written.
Returns
data Unsigned int16. 8 or 16 bit data.

Definition at line 185 of file spi_common_all.c.

References SPI_DR, SPI_SR, SPI_SR_RXNE, and spi_write().

Here is the call graph for this function: