Macros | Functions
Serial Peripheral Interface (SPI)

Macros

#define SPI_WPMR_WPKEY_PASSWD   SPI_WPMR_WPKEY((uint32_t) 0x535049)
 

Functions

int16_t spi_calc_baudrate_div (const uint32_t baudrate, uint32_t mck)
 Calculate the baudrate divider. More...
 
void spi_configure_cs_behavior (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_cs_behavior)
 Configure CS behavior for SPI transfer (spi_cs_behavior_t). More...
 
void spi_disable_clock (Spi *p_spi)
 Disable SPI clock. More...
 
void spi_enable_clock (Spi *p_spi)
 Enable SPI clock. More...
 
uint32_t spi_get_writeprotect_status (Spi *p_spi)
 Indicate write protect status. More...
 
spi_status_t spi_read (Spi *p_spi, uint16_t *us_data, uint8_t *p_pcs)
 Read the received data and it's peripheral chip select value. While SPI works in fixed peripheral select mode, the peripheral chip select value is meaningless. More...
 
int16_t spi_set_baudrate_div (Spi *p_spi, uint32_t ul_pcs_ch, uint8_t uc_baudrate_divider)
 Set Serial Clock Baud Rate divider value (SCBR). More...
 
void spi_set_bits_per_transfer (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_bits)
 Set number of bits per transfer. More...
 
void spi_set_clock_phase (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_phase)
 Set Data Capture Phase. More...
 
void spi_set_clock_polarity (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_polarity)
 Set clock default state. More...
 
void spi_set_delay_between_chip_select (Spi *p_spi, uint32_t ul_delay)
 Set delay between chip selects (in number of MCK clocks). If DLYBCS <= 6, 6 MCK clocks will be inserted by default. More...
 
void spi_set_peripheral_chip_select_value (Spi *p_spi, uint32_t ul_value)
 Set Peripheral Chip Select (PCS) value. More...
 
void spi_set_transfer_delay (Spi *p_spi, uint32_t ul_pcs_ch, uint8_t uc_dlybs, uint8_t uc_dlybct)
 Configure timing for SPI transfer. More...
 
void spi_set_writeprotect (Spi *p_spi, uint32_t ul_enable)
 Enable or disable write protection of SPI registers. More...
 
spi_status_t spi_write (Spi *p_spi, uint16_t us_data, uint8_t uc_pcs, uint8_t uc_last)
 Write the transmitted data with specified peripheral chip select value. More...
 

Detailed Description

See Quickstart guide for SAM SPI driver.

The SPI circuit is a synchronous serial data link that provides communication with external devices in Master or Slave mode. Connection to Peripheral DMA Controller channel capabilities optimizes data transfers.

Macro Definition Documentation

◆ SPI_WPMR_WPKEY_PASSWD

#define SPI_WPMR_WPKEY_PASSWD   SPI_WPMR_WPKEY((uint32_t) 0x535049)

Definition at line 52 of file spi.c.

Function Documentation

◆ spi_calc_baudrate_div()

int16_t spi_calc_baudrate_div ( const uint32_t  baudrate,
uint32_t  mck 
)

Calculate the baudrate divider.

Parameters
baudrateBaudrate value.
mckSPI module input clock frequency (MCK clock, Hz).
Returns
Divider or error code.
Return values
>0 Success.
<0 Error.

Definition at line 362 of file spi.c.

◆ spi_configure_cs_behavior()

void spi_configure_cs_behavior ( Spi p_spi,
uint32_t  ul_pcs_ch,
uint32_t  ul_cs_behavior 
)

Configure CS behavior for SPI transfer (spi_cs_behavior_t).

Parameters
p_spiPointer to an SPI instance.
ul_pcs_chPeripheral Chip Select channel (0~3).
ul_cs_behaviorBehavior of the Chip Select after transfer.

Definition at line 323 of file spi.c.

◆ spi_disable_clock()

void spi_disable_clock ( Spi p_spi)

Disable SPI clock.

Parameters
p_spiPointer to an SPI instance.

Definition at line 123 of file spi.c.

◆ spi_enable_clock()

void spi_enable_clock ( Spi p_spi)

Enable SPI clock.

Parameters
p_spiPointer to an SPI instance.

Definition at line 60 of file spi.c.

◆ spi_get_writeprotect_status()

uint32_t spi_get_writeprotect_status ( Spi p_spi)

Indicate write protect status.

Parameters
p_spiPointer to an SPI instance.
Returns
SPI_WPSR value.

Definition at line 444 of file spi.c.

◆ spi_read()

spi_status_t spi_read ( Spi p_spi,
uint16_t *  us_data,
uint8_t *  p_pcs 
)

Read the received data and it's peripheral chip select value. While SPI works in fixed peripheral select mode, the peripheral chip select value is meaningless.

Parameters
p_spiPointer to an SPI instance.
dataPointer to the location where to store the received data word.
p_pcsPointer to fill Peripheral Chip Select Value.
Return values
SPI_OKon Success.
SPI_ERROR_TIMEOUTon Time-out.

Definition at line 224 of file spi.c.

◆ spi_set_baudrate_div()

int16_t spi_set_baudrate_div ( Spi p_spi,
uint32_t  ul_pcs_ch,
uint8_t  uc_baudrate_divider 
)

Set Serial Clock Baud Rate divider value (SCBR).

Parameters
p_spiPointer to an SPI instance.
ul_pcs_chPeripheral Chip Select channel (0~3).
uc_baudrate_dividerBaudrate divider from MCK.
Returns
Return values
is0 Success.
is-1 Error.

Definition at line 385 of file spi.c.

◆ spi_set_bits_per_transfer()

void spi_set_bits_per_transfer ( Spi p_spi,
uint32_t  ul_pcs_ch,
uint32_t  ul_bits 
)

Set number of bits per transfer.

Parameters
p_spiPointer to an SPI instance.
ul_pcs_chPeripheral Chip Select channel (0~3).
ul_bitsNumber of bits (8~16), use the pattern defined in the device header file.

Definition at line 345 of file spi.c.

◆ spi_set_clock_phase()

void spi_set_clock_phase ( Spi p_spi,
uint32_t  ul_pcs_ch,
uint32_t  ul_phase 
)

Set Data Capture Phase.

Parameters
p_spiPointer to an SPI instance.
ul_pcs_chPeripheral Chip Select channel (0~3).
ul_phaseData capture on the rising/falling edge of clock.

Definition at line 307 of file spi.c.

◆ spi_set_clock_polarity()

void spi_set_clock_polarity ( Spi p_spi,
uint32_t  ul_pcs_ch,
uint32_t  ul_polarity 
)

Set clock default state.

Parameters
p_spiPointer to an SPI instance.
ul_pcs_chPeripheral Chip Select channel (0~3).
ul_polarityDefault clock state is logical one(high)/zero(low).

Definition at line 290 of file spi.c.

◆ spi_set_delay_between_chip_select()

void spi_set_delay_between_chip_select ( Spi p_spi,
uint32_t  ul_delay 
)

Set delay between chip selects (in number of MCK clocks). If DLYBCS <= 6, 6 MCK clocks will be inserted by default.

Parameters
p_spiPointer to an SPI instance.
ul_delayDelay between chip selects (in number of MCK clocks).

Definition at line 206 of file spi.c.

◆ spi_set_peripheral_chip_select_value()

void spi_set_peripheral_chip_select_value ( Spi p_spi,
uint32_t  ul_value 
)

Set Peripheral Chip Select (PCS) value.

Parameters
p_spiPointer to an SPI instance.
ul_valuePeripheral Chip Select value. If PCS decode mode is not used, use spi_get_pcs to build the value to use. On reset the decode mode is not enabled. The decode mode can be enabled/disabled by follow functions: spi_enable_peripheral_select_decode, spi_disable_peripheral_select_decode.

Definition at line 193 of file spi.c.

◆ spi_set_transfer_delay()

void spi_set_transfer_delay ( Spi p_spi,
uint32_t  ul_pcs_ch,
uint8_t  uc_dlybs,
uint8_t  uc_dlybct 
)

Configure timing for SPI transfer.

Parameters
p_spiPointer to an SPI instance.
ul_pcs_chPeripheral Chip Select channel (0~3).
uc_dlybsDelay before SPCK (in number of MCK clocks).
uc_dlybctDelay between consecutive transfers (in number of MCK clocks).

Definition at line 405 of file spi.c.

◆ spi_set_writeprotect()

void spi_set_writeprotect ( Spi p_spi,
uint32_t  ul_enable 
)

Enable or disable write protection of SPI registers.

Parameters
p_spiPointer to an SPI instance.
ul_enable1 to enable, 0 to disable.

Definition at line 420 of file spi.c.

◆ spi_write()

spi_status_t spi_write ( Spi p_spi,
uint16_t  us_data,
uint8_t  uc_pcs,
uint8_t  uc_last 
)

Write the transmitted data with specified peripheral chip select value.

Parameters
p_spiPointer to an SPI instance.
us_dataThe data to transmit.
uc_pcsPeripheral Chip Select Value while SPI works in peripheral select mode, otherwise it's meaningless.
uc_lastIndicate whether this data is the last one while SPI is working in variable peripheral select mode.
Return values
SPI_OKon Success.
SPI_ERROR_TIMEOUTon Time-out.

Definition at line 257 of file spi.c.



inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:18:01