|
SAM4SD32 (SAM4S-EK2)
|
See Quickstart guide for SAM SPI driver. More...
Topics | |
| Legacy SPI group alias | |
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. | |
| 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). | |
| void | spi_disable_clock (Spi *p_spi) |
| Disable SPI clock. | |
| void | spi_enable_clock (Spi *p_spi) |
| Enable SPI clock. | |
| uint32_t | spi_get_writeprotect_status (Spi *p_spi) |
| Indicate write protect status. | |
| 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. | |
| 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). | |
| void | spi_set_bits_per_transfer (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_bits) |
| Set number of bits per transfer. | |
| void | spi_set_clock_phase (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_phase) |
| Set Data Capture Phase. | |
| void | spi_set_clock_polarity (Spi *p_spi, uint32_t ul_pcs_ch, uint32_t ul_polarity) |
| Set clock default state. | |
| void | spi_set_delay_between_chip_select (Spi *p_spi, uint32_t ul_delay) |
| Set delay between chip selects (in number of MCK clocks). | |
| void | spi_set_peripheral_chip_select_value (Spi *p_spi, uint32_t ul_value) |
| Set Peripheral Chip Select (PCS) value. | |
| 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. | |
| void | spi_set_writeprotect (Spi *p_spi, uint32_t ul_enable) |
| Enable or disable write protection of SPI registers. | |
| 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. | |
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.
| #define SPI_WPMR_WPKEY_PASSWD SPI_WPMR_WPKEY((uint32_t) 0x535049) |
Definition at line 52 of file spi.c.
Referenced by spi_set_writeprotect().
| int16_t spi_calc_baudrate_div | ( | const uint32_t | baudrate, |
| uint32_t | mck ) |
Calculate the baudrate divider.
| baudrate | Baudrate value. |
| mck | SPI module input clock frequency (MCK clock, Hz). |
| > | 0 Success. |
| < | 0 Error. |
Definition at line 362 of file spi.c.
| 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).
| p_spi | Pointer to an SPI instance. |
| ul_pcs_ch | Peripheral Chip Select channel (0~3). |
| ul_cs_behavior | Behavior of the Chip Select after transfer. |
Definition at line 323 of file spi.c.
References SPI_CS_KEEP_LOW, SPI_CS_RISE_FORCED, SPI_CS_RISE_NO_TX, Spi::SPI_CSR, SPI_CSR_CSAAT, and SPI_CSR_CSNAAT.
| void spi_disable_clock | ( | Spi * | p_spi | ) |
Disable SPI clock.
| p_spi | Pointer to an SPI instance. |
Definition at line 123 of file spi.c.
References ID_SPI.
| void spi_enable_clock | ( | Spi * | p_spi | ) |
Enable SPI clock.
| p_spi | Pointer to an SPI instance. |
Definition at line 60 of file spi.c.
References ID_SPI.
| uint32_t spi_get_writeprotect_status | ( | Spi * | p_spi | ) |
Indicate write protect status.
| p_spi | Pointer to an SPI instance. |
Definition at line 444 of file spi.c.
References Spi::SPI_WPSR.
| 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.
| p_spi | Pointer to an SPI instance. |
| us_data | Pointer to the location where to store the received data word. |
| p_pcs | Pointer to fill Peripheral Chip Select Value. |
| SPI_OK | on Success. |
| SPI_ERROR_TIMEOUT | on Time-out. |
Definition at line 224 of file spi.c.
References SPI_ERROR_TIMEOUT, spi_get_peripheral_select_mode(), SPI_OK, Spi::SPI_RDR, SPI_RDR_PCS_Msk, SPI_RDR_PCS_Pos, SPI_RDR_RD_Msk, Spi::SPI_SR, SPI_SR_RDRF, and SPI_TIMEOUT.
| 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).
| p_spi | Pointer to an SPI instance. |
| ul_pcs_ch | Peripheral Chip Select channel (0~3). |
| uc_baudrate_divider | Baudrate divider from MCK. |
| 0 | Success. |
| -1 | Error. |
Definition at line 385 of file spi.c.
References Spi::SPI_CSR, SPI_CSR_SCBR, and SPI_CSR_SCBR_Msk.
| void spi_set_bits_per_transfer | ( | Spi * | p_spi, |
| uint32_t | ul_pcs_ch, | ||
| uint32_t | ul_bits ) |
Set number of bits per transfer.
| p_spi | Pointer to an SPI instance. |
| ul_pcs_ch | Peripheral Chip Select channel (0~3). |
| ul_bits | Number of bits (8~16), use the pattern defined in the device header file. |
Definition at line 345 of file spi.c.
References Spi::SPI_CSR, and SPI_CSR_BITS_Msk.
| void spi_set_clock_phase | ( | Spi * | p_spi, |
| uint32_t | ul_pcs_ch, | ||
| uint32_t | ul_phase ) |
Set Data Capture Phase.
| p_spi | Pointer to an SPI instance. |
| ul_pcs_ch | Peripheral Chip Select channel (0~3). |
| ul_phase | Data capture on the rising/falling edge of clock. |
Definition at line 307 of file spi.c.
References Spi::SPI_CSR, and SPI_CSR_NCPHA.
| void spi_set_clock_polarity | ( | Spi * | p_spi, |
| uint32_t | ul_pcs_ch, | ||
| uint32_t | ul_polarity ) |
Set clock default state.
| p_spi | Pointer to an SPI instance. |
| ul_pcs_ch | Peripheral Chip Select channel (0~3). |
| ul_polarity | Default clock state is logical one(high)/zero(low). |
Definition at line 290 of file spi.c.
References Spi::SPI_CSR, and SPI_CSR_CPOL.
| 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.
| p_spi | Pointer to an SPI instance. |
| ul_delay | Delay between chip selects (in number of MCK clocks). |
Definition at line 206 of file spi.c.
References Spi::SPI_MR, SPI_MR_DLYBCS, and SPI_MR_DLYBCS_Msk.
| void spi_set_peripheral_chip_select_value | ( | Spi * | p_spi, |
| uint32_t | ul_value ) |
Set Peripheral Chip Select (PCS) value.
| p_spi | Pointer to an SPI instance. |
| ul_value | Peripheral 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.
References Spi::SPI_MR, SPI_MR_PCS, and SPI_MR_PCS_Msk.
| 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.
| p_spi | Pointer to an SPI instance. |
| ul_pcs_ch | Peripheral Chip Select channel (0~3). |
| uc_dlybs | Delay before SPCK (in number of MCK clocks). |
| uc_dlybct | Delay between consecutive transfers (in number of MCK clocks). |
Definition at line 405 of file spi.c.
References Spi::SPI_CSR, SPI_CSR_DLYBCT, SPI_CSR_DLYBCT_Msk, SPI_CSR_DLYBS, and SPI_CSR_DLYBS_Msk.
| void spi_set_writeprotect | ( | Spi * | p_spi, |
| uint32_t | ul_enable ) |
Enable or disable write protection of SPI registers.
| p_spi | Pointer to an SPI instance. |
| ul_enable | 1 to enable, 0 to disable. |
Definition at line 420 of file spi.c.
References Spi::SPI_WPMR, SPI_WPMR_WPEN, and SPI_WPMR_WPKEY_PASSWD.
| 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.
| p_spi | Pointer to an SPI instance. |
| us_data | The data to transmit. |
| uc_pcs | Peripheral Chip Select Value while SPI works in peripheral select mode, otherwise it's meaningless. |
| uc_last | Indicate whether this data is the last one while SPI is working in variable peripheral select mode. |
| SPI_OK | on Success. |
| SPI_ERROR_TIMEOUT | on Time-out. |
Definition at line 257 of file spi.c.
References SPI_ERROR_TIMEOUT, spi_get_peripheral_select_mode(), SPI_OK, Spi::SPI_SR, SPI_SR_TDRE, Spi::SPI_TDR, SPI_TDR_LASTXFER, SPI_TDR_PCS, SPI_TDR_TD, and SPI_TIMEOUT.