![]() |
RZ Flexible Software Package Documentation
Release v4.3.0
|
|
Functions | |
| fsp_err_t | R_SCI_SPI_Open (spi_ctrl_t *p_ctrl, spi_cfg_t const *const p_cfg) |
| fsp_err_t | R_SCI_SPI_Read (spi_ctrl_t *const p_ctrl, void *p_dest, uint32_t const length, spi_bit_width_t const bit_width) |
| fsp_err_t | R_SCI_SPI_Write (spi_ctrl_t *const p_ctrl, void const *p_src, uint32_t const length, spi_bit_width_t const bit_width) |
| fsp_err_t | R_SCI_SPI_WriteRead (spi_ctrl_t *const p_ctrl, void const *p_src, void *p_dest, uint32_t const length, spi_bit_width_t const bit_width) |
| fsp_err_t | R_SCI_SPI_CallbackSet (spi_ctrl_t *const p_ctrl, void(*p_callback)(spi_callback_args_t *), void *const p_context, spi_callback_args_t *const p_callback_memory) |
| fsp_err_t | R_SCI_SPI_Close (spi_ctrl_t *const p_ctrl) |
| fsp_err_t | R_SCI_SPI_CalculateBitrate (uint32_t bitrate, sci_spi_clock_source_t clock_source, sci_spi_div_setting_t *sclk_div) |
Driver for the SCI peripheral on RZ microprocessor. 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. |
| DMAC Support |
| Enabled | If support for transferring data using the DMAC will be compiled in. Even if DMAC support is enabled, DMAC is not used without adding DMAC driver. |
| Nested Interrupt (Multiplex Interrupt) |
| Disabled | Enable nested interrupt for a single driver. |
| FIFO Support |
| Disabled | Enable FIFO support for the SCI_SPI module. |
| Configuration | Options | Default | Description |
|---|---|---|---|
| Name | Name must be a valid C symbol | g_sci_spi0 | Module name. |
| Channel | Value must be a non-negative integer | 0 | Select the SCI channel. Do not select the safety channel when using DMAC. |
| Operating Mode |
| Master | Select the SPI operating mode. |
| Clock Phase |
| Data sampling on odd edge, data variation on even edge | Select the clock edge to sample data. |
| Clock Polarity |
| Low when idle | Select clock level when idle. |
| Bit Order |
| MSB First | Select the data bit order. |
| Clock Source |
| SCInASYNCCLK | Select whether the SCInASYNCCLK or peripheral clock (PCLKM) is used for generating the SCK frequency. |
| Callback | Name must be a valid C symbol | sci_spi_callback | A user callback function that is called from the sci spi interrupts when a transfer is completed or an error has occurred. |
| Receive Interrupt Priority | MCU Specific Options | Select the receive interrupt priority. | |
| Transmit Interrupt Priority | MCU Specific Options | Select the transmit interrupt priority. | |
| Transmit End Interrupt Priority | MCU Specific Options | Select the transmit end interrupt priority. | |
| Error Interrupt Priority | MCU Specific Options | Select the error interrupt priority. | |
| Bitrate | Value must be an integer greater than 0 | 8000000 | Enter the desired bitrate. If the requested bitrate cannot be achieved, the settings with the largest possible value that is less than or equal to the requested bitrate is used. The actual bitrate is printed in a comment in the generated sci_spi_extended_cfg_t structure. |
| Transmit FIFO Trigger Level |
| Disabled | Select Disabled to disable the TX FIFO trigger, or 15 (Max) to trigger the reload when the FIFO is full or after 15 bit times with no data. |
| Receive Sampling Timing Adjustment (Master Only) |
| Default (No Delay) | Select the sampling timing delay of the RXDn pin (master mode only). Configuring this property may be required at high bitrates for the master to sample the received data accurately. This setting has no effect in slave mode. |
The SCI peripheral uses the SCInASYNCCLK or PCLKM for communication and PCLKM for internal operations. Both can be configured via the Clocks tab of the Configuration editor or by using the CGC Interface at run-time.
This module uses SCIn_MOSI, SCIn_MISO, SCIn_SPCK, and SCIn_SS 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. This may also result in SPI_EVENT_ERR_READ_OVERFLOW errors.
In order to improve performance at high bit rates, consider the following recommendations:
Also note when using DMAC for data transfer, SCI SPI can experience overrun error if the application makes heavy use of another DMAC instance. This is because the arbitration between different triggers/transfers in DMAC is done based on interrupt/trigger priority. Overrun error can be averted with one of the following options:
After every byte, the SCI SPI peripheral generates a transmit buffer empty interrupt and a receive buffer full interrupt. Whenever possible, the SCI_SPI module handles both interrupts in the receive buffer full interrupt. This improves performance when the DMAC is not being used.
Source and destination buffers must either be allocated to a non-cacheable region, or, if placed in a cacheable region, be managed via explicit cache maintenance operations (clean/invalidate) to ensure data coherency (This involves cleaning the cache before starting the transmission and invalidating it once the transmission is completed). In the case of the write-back policy, when a destination buffer is placed in a cacheable region, it must be aligned with 64 bytes. See Memory attributes for details.
This is a basic example of minimal use of the SCI_SPI in an application.
Classes | |
| struct | st_sci_spi_div_setting |
| struct | st_sci_spi_extended_cfg |
| struct | st_sci_spi_instance_ctrl |
Typedefs | |
| typedef struct st_sci_spi_div_setting | sci_spi_div_setting_t |
| typedef struct st_sci_spi_extended_cfg | sci_spi_extended_cfg_t |
| typedef struct st_sci_spi_instance_ctrl | sci_spi_instance_ctrl_t |
Enumerations | |
| enum | sci_spi_clock_source_t |
| enum | sci_spi_rx_sampling_delay_t |
| enum | sci_spi_tx_fifo_trigger_t |
| struct RZN::st_sci_spi_div_setting |
Settings for adjusting the SPI CLK.
| struct RZN::st_sci_spi_extended_cfg |
SCI SPI extended configuration
| Class Members | ||
|---|---|---|
| sci_spi_div_setting_t | clk_div | |
| sci_spi_clock_source_t | clock_source |
Clock source to generate SCK can either be selected as PCLKM or SCInASYNCCLK. |
| sci_spi_rx_sampling_delay_t | rx_sampling_delay |
Receive sampling timing adjustment. |
| sci_spi_tx_fifo_trigger_t | tx_fifo_trigger |
Transmit FIFO trigger level. |
| void * | p_reg | Register base address. |
| struct RZN::st_sci_spi_instance_ctrl |
SPI instance control block. DO NOT INITIALIZE.
| typedef struct st_sci_spi_div_setting sci_spi_div_setting_t |
Settings for adjusting the SPI CLK. Please refer to the struct st_sci_spi_div_setting.
| typedef struct st_sci_spi_extended_cfg sci_spi_extended_cfg_t |
SCI SPI extended configuration. Please refer to the struct st_sci_spi_extended_cfg.
| typedef struct st_sci_spi_instance_ctrl sci_spi_instance_ctrl_t |
SPI instance control block. DO NOT INITIALIZE. Please refer to the struct st_sci_spi_instance_ctrl.
Source clock selection options for SCI.
Adjustment value for receive sampling timing delay for RXDn
| fsp_err_t R_SCI_SPI_Open | ( | spi_ctrl_t * | p_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_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_INVALID_ARGUMENT | Invalid input parameter. |
| FSP_ERR_UNSUPPORTED | Fifo mode is requested but a transfer interface is not used |
| fsp_err_t R_SCI_SPI_Read | ( | spi_ctrl_t *const | p_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_ctrl | Pointer to the control structure. | |
| p_dest | Pointer to the destination buffer. | |
| [in] | length | The number of bytes to transfer. |
| [in] | bit_width | Invalid for SCI_SPI (Set to 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_SCI_SPI_Write | ( | spi_ctrl_t *const | p_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_ctrl | Pointer to the control structure. | |
| p_src | Pointer to the source buffer. | |
| [in] | length | The number of bytes to transfer. |
| [in] | bit_width | Invalid for SCI_SPI (Set to 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_SCI_SPI_WriteRead | ( | spi_ctrl_t *const | p_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_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 | Invalid for SCI_SPI (Set to 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_SCI_SPI_CallbackSet | ( | spi_ctrl_t *const | p_ctrl, |
| void(*)(spi_callback_args_t *) | p_callback, | ||
| void *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_SCI_SPI_Close | ( | spi_ctrl_t *const | p_ctrl | ) |
Disable the SCI channel and set the instance as not open. Implements spi_api_t::close.
| p_ctrl | Pointer to an opened instance. |
| FSP_SUCCESS | Channel successfully closed. |
| FSP_ERR_ASSERTION | The parameter p_ctrl is NULL. |
| FSP_ERR_NOT_OPEN | The channel has not been opened. Open the channel first. |
| fsp_err_t R_SCI_SPI_CalculateBitrate | ( | uint32_t | bitrate, |
| sci_spi_clock_source_t | clock_source, | ||
| sci_spi_div_setting_t * | sclk_div | ||
| ) |
Calculate the register settings required to achieve the desired bitrate.
| [in] | bitrate | bitrate [bps]. For example, 250,000; 500,00; 2,500,000; etc. |
| clock_source | clock source (PCLKM or SCInASYNCCLK) used for bit rate calculation. | |
| sclk_div | Pointer to sci_spi_div_setting_t used to configure baudrate settings. |
| FSP_SUCCESS | Baud rate is set successfully. |
| FSP_ERR_ASSERTION | Baud rate is not achievable. |
| FSP_ERR_INVALID_ARGUMENT | Invalid input parameter. |