RA Flexible Software Package Documentation
Release v5.6.0
|
|
Functions | |
fsp_err_t | R_SAU_SPI_Open (spi_ctrl_t *p_api_ctrl, spi_cfg_t const *const p_cfg) |
fsp_err_t | R_SAU_SPI_Read (spi_ctrl_t *const p_api_ctrl, void *p_dest, uint32_t const length, spi_bit_width_t const bit_width) |
fsp_err_t | R_SAU_SPI_Write (spi_ctrl_t *const p_api_ctrl, void const *p_src, uint32_t const length, spi_bit_width_t const bit_width) |
fsp_err_t | R_SAU_SPI_WriteRead (spi_ctrl_t *const p_api_ctrl, void const *p_src, void *p_dest, uint32_t const length, spi_bit_width_t const bit_width) |
fsp_err_t | R_SAU_SPI_CallbackSet (spi_ctrl_t *const p_api_ctrl, void(*p_callback)(spi_callback_args_t *), void const *const p_context, spi_callback_args_t *const p_callback_memory) |
fsp_err_t | R_SAU_SPI_Close (spi_ctrl_t *const p_api_ctrl) |
fsp_err_t | R_SAU_SPI_CalculateBitrate (uint32_t bitrate, sau_spi_div_setting_t *sclk_div, uint8_t sau_unit, uint8_t channel) |
Driver for the SAU peripheral on RA MCUs. This module implements the SPI Interface.
Configuration | Options | Default | Description |
---|---|---|---|
Parameter Checking |
| Default (BSP) | If selected code for parameter checking is included in the build. |
Critical Section Guarding |
| Disabled | Enable critical section guarding around peripheral configuration updates. This should be enabled if the R_SAU_I2C or R_SAU_UART module is being used simultaneously with this module. |
Enable Single Channel |
| Disabled | Enable single channel to reduce code size if only one channel (00, 11, or 20) is to be configured for SAU SPI. |
Transfer Operating Mode |
| Transmission/Reception | Select transfer operation mode. |
DTC Support |
| Disable | Enable DTC support for the SAU SPI module. |
Configuration | Options | Default | Description |
---|---|---|---|
Name | Name must be a valid C symbol | g_spi0 | Module name. |
Channel | MCU Specific Options | Select the SAU channel. | |
Operating Mode |
| Master | Select the SPI operating mode. |
Operation Clock |
| CK0 | Select the operation clock. Use the Clocks tab to set the operation clock divider. |
Transfer Mode |
| Single transfer mode | Select transfer mode in transfer end interrupt. But buffer empty interrupt (in continuous transfer mode) cannot be selected in Slave Reception. |
Bit Order |
| MSB First | Select of data transfer sequence. |
Data Phase |
| Data sampling on odd edge, data variation on even edge | Select when data output shall start compared with the serial clock operation. |
Clock Phase |
| High when idle | Select clock phase. |
Bitrate | Value must be an integer greater than 0 | 500000 | Enter the desired bitrate. If the requested bitrate cannot be achieved, adjust the operation clock frequency until the bitrate is achievable. The calculated bitrate is printed in a comment in the generated sau_spi_extended_cfg_t structure. |
Callback | Name must be a valid C symbol | sau_spi_callback | A user callback function that is called from the sau spi interrupts when a transfer is completed or an error has occurred. |
Transmit End Interrupt Priority | MCU Specific Options | Select the transmit end interrupt priority. |
The SAU clock uses the system clock (ICLK) as its clock source.
A prescaler is applied to the ICLK in order to produce the operation clock frequency. The operation clock is used to generate the desired transfer period of the SAU module.
SAU operation clocks are shared among all channels within a SAU unit. Check the Hardware User's Manual for your MCU for available units and channels. SAU operation clock dividers are configurable in the Clocks tab.
The operation clock dividers are named SAU CKmn where m is the SAU unit, and n is the operation clock. For example, SAU CK01 applies to all SAU0 instances using CK1 as the operation clock (m=0, n=1).
The following table illustrates the settings of the Clock Phase/Polarity corresponding SCRmn register DCP[1:0] bits in the SAU SPI.
Clock Phase | Clock Polarity | DCP[1:0] Value |
---|---|---|
Data sampling on odd edge, data variation on even edge | High when idle | 0b00 |
Data sampling on odd edge, data variation on even edge | Low when idle | 0b01 |
Data sampling on even edge, data variation on odd edge | High when idle | 0b10 |
Data sampling on even edge, data variation on odd edge | Low when idle | 0b11 |
This module uses SCKmn, SOmn, and SImn pins to communicate with on board devices.
The transfer complete event is triggered when all of the data has been transferred. In slave mode if the SS pin is de-asserted then no transfer complete event is generated until the SS pin is asserted and the remaining data is transferred.
At high bit rates, interrupts may not be able to service transfers fast enough. In master mode this means there will be a delay between each data frame. In slave mode this could result in RX Overflow errors.
To improve performance at high bit rates, it is recommended that the instance be configured to service transfers using the DTC.
If only SAU channel 00 is to be used for I2C or SPI or UART, enable single channel can reduce the code size.
The relationship between operation clock frequency and bitrate is: bitrate = f_mck / [ 2 * (SDRmn.STCLK + 1) ]
where:
SDRmn.STCLK
is an integer in the range [0, 127] for SAU SPIf_mck
is the operation clock (SAU CKmn) frequencyBy plugging in the minimum and maximum SDRmn.STCLK
values, the range of bitrates for a given operation clock frequency can be obtained.
Note that due to STCLK being set as discrete integers, the actual bitrate may not be exact. The actual bitrate and percent errors can be calculated by the formulas:
Using the fastest possible operation clock for the desired bitrate will result in the lowest deviation from the requested bitrate. Set the CKmn operation clock divider in the Clocks tab to select the desired operation clock frequency.
The function R_SAU_SPI_CalculateBitrate can be used at runtime to calculate alternate bitrate settings.
This function computes settings with both operation clocks CK0 and CK1. If valid settings are possible with both clocks, it selects the settings and clock that would produce the lowest error.
Set the divisors for CK0 and CK01 in the clocks tab such that all required bitrate settings for the application are possible. A large range of bitrates can be achieved by having one "slow" operation clock for low speed modes and one "fast" operation clock for high speed modes.
This is a basic example of minimal use of the SAU_SPI in an application.
#define | SAU_SPI_TRANSFER_MODE_RECEPTION |
Reception only. | |
#define | SAU_SPI_TRANSFER_MODE_TRANSMISSION |
Transmission only. | |
#define | SAU_SPI_TRANSFER_MODE_TRANSMISSION_RECEPTION |
Transmission/reception. | |
enum | sau_spi_operation_clock_t |
enum | sau_spi_transfer_mode_t |
enum | sau_spi_data_phase_t |
enum | sau_spi_clock_phase_t |
Selection of operating clock (fMCK) of channel
Selection of transfer mode of channel
enum sau_spi_data_phase_t |
Data phase
Clock phase
fsp_err_t R_SAU_SPI_Open | ( | spi_ctrl_t * | p_api_ctrl, |
spi_cfg_t const *const | p_cfg | ||
) |
Initialize a channel for SPI communication mode. Implements spi_api_t::open.
This function performs the following tasks:
p_api_ctrl | Pointer to the control structure. |
p_cfg | Pointer to a configuration structure. |
FSP_SUCCESS | Channel initialized successfully. |
FSP_ERR_ASSERTION | An input parameter is invalid or NULL. |
FSP_ERR_ALREADY_OPEN | The instance has already been opened. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | The channel number is invalid. |
fsp_err_t R_SAU_SPI_Read | ( | spi_ctrl_t *const | p_api_ctrl, |
void * | p_dest, | ||
uint32_t const | length, | ||
spi_bit_width_t const | bit_width | ||
) |
Receive data from an SPI device. Implements spi_api_t::read.
The function performs the following tasks:
p_api_ctrl | Pointer to the control structure. | |
p_dest | Pointer to the destination buffer. | |
[in] | length | The number of bytes to transfer. |
[in] | bit_width | Data frame length (Set to SPI_BIT_WIDTH_7_BITS or SPI_BIT_WIDTH_8_BITS). |
FSP_SUCCESS | Read operation successfully completed. |
FSP_ERR_ASSERTION | One of the following invalid parameters passed:
|
FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
FSP_ERR_UNSUPPORTED | The given bit_width is not supported. |
FSP_ERR_IN_USE | A transfer is already in progress. |
fsp_err_t R_SAU_SPI_Write | ( | spi_ctrl_t *const | p_api_ctrl, |
void const * | p_src, | ||
uint32_t const | length, | ||
spi_bit_width_t const | bit_width | ||
) |
Transmit data to a SPI device. Implements spi_api_t::write.
The function performs the following tasks:
p_api_ctrl | Pointer to the control structure. | |
p_src | Pointer to the source buffer. | |
[in] | length | The number of bytes to transfer. |
[in] | bit_width | Data frame length (Set to SPI_BIT_WIDTH_7_BITS or SPI_BIT_WIDTH_8_BITS). |
FSP_SUCCESS | Write operation successfully completed. |
FSP_ERR_ASSERTION | One of the following invalid parameters passed:
|
FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
FSP_ERR_UNSUPPORTED | The given bit_width is not supported. |
FSP_ERR_IN_USE | A transfer is already in progress. |
fsp_err_t R_SAU_SPI_WriteRead | ( | spi_ctrl_t *const | p_api_ctrl, |
void const * | p_src, | ||
void * | p_dest, | ||
uint32_t const | length, | ||
spi_bit_width_t const | bit_width | ||
) |
Simultaneously transmit data to SPI device while receiving data from SPI device (full duplex). Implements spi_api_t::writeRead.
The function performs the following tasks:
p_api_ctrl | Pointer to the control structure. | |
p_src | Pointer to the source buffer. | |
p_dest | Pointer to the destination buffer. | |
[in] | length | The number of bytes to transfer. |
[in] | bit_width | Data frame length (Set to SPI_BIT_WIDTH_7_BITS or SPI_BIT_WIDTH_8_BITS). |
FSP_SUCCESS | Write operation successfully completed. |
FSP_ERR_ASSERTION | One of the following invalid parameters passed:
|
FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
FSP_ERR_UNSUPPORTED | The given bit_width is not supported. |
FSP_ERR_IN_USE | A transfer is already in progress. |
fsp_err_t R_SAU_SPI_CallbackSet | ( | spi_ctrl_t *const | p_api_ctrl, |
void(*)(spi_callback_args_t *) | p_callback, | ||
void const *const | p_context, | ||
spi_callback_args_t *const | p_callback_memory | ||
) |
Updates the user callback and has option of providing memory for callback structure. Implements spi_api_t::callbackSet
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
fsp_err_t R_SAU_SPI_Close | ( | spi_ctrl_t *const | p_api_ctrl | ) |
Disable the SAU channel and set the instance as not open. Implements spi_api_t::close.
p_api_ctrl | Pointer to an opened instance. |
FSP_SUCCESS | Channel successfully closed. |
FSP_ERR_ASSERTION | The parameter p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
fsp_err_t R_SAU_SPI_CalculateBitrate | ( | uint32_t | bitrate, |
sau_spi_div_setting_t * | sclk_div, | ||
uint8_t | sau_unit, | ||
uint8_t | channel | ||
) |
Calculate the register settings required to achieve the desired bitrate.
[in] | bitrate | bitrate [bps]. For example, 250,000; 500,00; 16,000,000 (max), etc. |
[out] | sclk_div | Pointer to sau_spi_div_setting_t used to configure baudrate settings. |
sau_unit | SAU unit. | |
channel | SAU channel. |
FSP_SUCCESS | Bitrate is calculated successfully. |
FSP_ERR_ASSERTION | Bitrate is not achievable or not valid for the selected unit/channel. |