![]() |
MT2523 API Reference
LinkIt SDK v4
|
This section introduces the Serial Peripheral Interface Master (SPI_Master) APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enums, structures and functions. More...
This section introduces the Serial Peripheral Interface Master (SPI_Master) APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enums, structures and functions.
| Terms | Details |
|---|---|
| DMA | Direct Memory Access. DMA is a feature of computer systems that allows certain hardware subsystems to access main system memory independent from the central processing unit (CPU). |
| FIFO | First In, First Out. FIFO is a method for organizing and manipulating a data buffer, where the first entry, or 'head' of the queue, is processed first. |
| GPIO | General Purpose Inputs-Outputs. For more details, please refer to GPIO. |
| NVIC | Nested Vectored Interrupt Controller. NVIC is the interrupt controller of ARM Cortex-M series processors. For more details, please refer to ARM Cortex-M4 technical reference manual. |
| SPI | Serial Peripheral Interface. The Serial Peripheral Interface bus is a synchronous serial communication interface specification used for short distance communication. For more information, please check Serial Peripheral Interface Bus in Wikipedia. |
This controller supports a wide range of SPI interface devices, including full-duplex transaction ability to communicate with both half-duplex and full-duplex devices. For half-duplex devices, the data flow direction is not relevant for the software. Hardware provides access for various timing adjustments.
Polling mode transaction: In polling mode, hal_spi_master_send_polling() and hal_spi_master_send_and_receive_polling() return a value once the transaction is complete. Then the user checks the output of the return value for the transaction result and error handling if any.
See Software architecture of the SPI for the software architecture of polling mode.
DMA mode transaction: In DMA mode, hal_spi_master_send_dma() and hal_spi_master_send_and_receive_dma() return a value once the SPI hardware register is assigned and the DMA configured. During this process the transaction is usually incomplete, once it completes, an interrupt is triggered and a related user callback is called in the SPI interrupt service routine.
See Software architecture of the SPI for the software architecture of DMA mode.
DMA blocking mode transaction: In DMA blocking mode, hal_spi_master_send_dma_blocking() and hal_spi_master_send_and_receive_dma_blocking() return a value once the SPI DMA transaction is complete after hardware register is assigned and the DMA configured.
See Software architecture of the SPI for the software architecture of DMA blocking mode.
Functions | |
| hal_spi_master_status_t | hal_spi_master_init (hal_spi_master_port_t master_port, hal_spi_master_config_t *spi_config) |
| This function is mainly used to initialize the SPI master and set user defined common parameters like clock frequency, bit order, clock polarity, clock phase and default settings. More... | |
| hal_spi_master_status_t | hal_spi_master_deinit (hal_spi_master_port_t master_port) |
| This function resets the SPI master, gates its clock, disables interrupts. More... | |
| hal_spi_master_status_t | hal_spi_master_set_advanced_config (hal_spi_master_port_t master_port, hal_spi_master_advanced_config_t *advanced_config) |
| SPI master advanced configuration function. More... | |
| hal_spi_master_status_t | hal_spi_master_send_polling (hal_spi_master_port_t master_port, uint8_t *data, uint32_t size) |
| This function is used to send data synchronously with FIFO mode. More... | |
| hal_spi_master_status_t | hal_spi_master_send_dma (hal_spi_master_port_t master_port, uint8_t *data, uint32_t size) |
| This function is used to send data asynchronously with DMA mode. More... | |
| hal_spi_master_status_t | hal_spi_master_send_dma_blocking (hal_spi_master_port_t master_port, uint8_t *data, uint32_t size) |
| This function is used to send data synchronously with DMA mode. More... | |
| hal_spi_master_status_t | hal_spi_master_send_and_receive_polling (hal_spi_master_port_t master_port, hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config) |
| This function simultaneously sends and receives data in the FIFO mode. More... | |
| hal_spi_master_status_t | hal_spi_master_send_and_receive_dma (hal_spi_master_port_t master_port, hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config) |
| This function is used to send and receive data asynchronously with DMA mode. More... | |
| hal_spi_master_status_t | hal_spi_master_send_and_receive_dma_blocking (hal_spi_master_port_t master_port, hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config) |
| This function simultaneously sends and receives data in the DMA mode. More... | |
| hal_spi_master_status_t | hal_spi_master_get_running_status (hal_spi_master_port_t master_port, hal_spi_master_running_status_t *running_status) |
| This function gets current running status of the SPI master. More... | |
| hal_spi_master_status_t | hal_spi_master_set_chip_select_timing (hal_spi_master_port_t master_port, hal_spi_master_chip_select_timing_t chip_select_timing) |
| This function is used to configure SPI master chip select timing parameter. More... | |
| hal_spi_master_status_t | hal_spi_master_set_deassert (hal_spi_master_port_t master_port, hal_spi_master_deassert_t deassert) |
| SPI master chip select de-assertion mode configuration. More... | |
| hal_spi_master_status_t | hal_spi_master_set_macro_selection (hal_spi_master_port_t master_port, hal_spi_master_macro_select_t macro_select) |
| SPI master macro group configuration. More... | |
| hal_spi_master_status_t | hal_spi_master_register_callback (hal_spi_master_port_t master_port, hal_spi_master_callback_t callback, void *user_data) |
| This function is used to register user's callback to SPI master driver. More... | |
Modules | |
| Define | |
| Enum | |
| Struct | |
| Typedef | |
| hal_spi_master_status_t hal_spi_master_deinit | ( | hal_spi_master_port_t | master_port | ) |
This function resets the SPI master, gates its clock, disables interrupts.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| hal_spi_master_status_t hal_spi_master_get_running_status | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_running_status_t * | running_status | ||
| ) |
This function gets current running status of the SPI master.
Note this API can only be called after hal_spi_master_init().
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [out] | running_status | is the current running status. HAL_SPI_MASTER_BUSY, the SPI master is in busy status; HAL_SPI_MASTER_IDLE, the SPI master is in idle status, user can use it to transfer data now. |
| hal_spi_master_status_t hal_spi_master_init | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_config_t * | spi_config | ||
| ) |
This function is mainly used to initialize the SPI master and set user defined common parameters like clock frequency, bit order, clock polarity, clock phase and default settings.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | spi_config | is the SPI master configure parameters. Details are described at hal_spi_master_config_t. |
| hal_spi_master_status_t hal_spi_master_register_callback | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_callback_t | callback, | ||
| void * | user_data | ||
| ) |
This function is used to register user's callback to SPI master driver.
This function should be called when user wants to use the DMA mode, the callback will be called in SPI interrupt service routine.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | callback | is the callback function given by user, which will be called at SPI master interrupt service routine. |
| [in] | user_data | is a parameter given by user and will pass to user while the callback function is called. See the last parameter of hal_spi_master_callback_t. |
| hal_spi_master_status_t hal_spi_master_send_and_receive_dma | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_send_and_receive_config_t * | spi_send_and_receive_config | ||
| ) |
This function is used to send and receive data asynchronously with DMA mode.
This function returns immediately, before calling this function, call hal_spi_master_register_callback() to register a callback, once the transaction is complete, the callback will be called in the SPI ISR.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | spi_send_and_receive_config | is the structure that contains data buffer and data size, please refer to hal_spi_master_send_and_receive_config_t , for more details. Check the SPI device's datasheet to determine if the data is sent or received. For example, if ADIS16375 is used in full duplex communication mode, the data is received, while send command is valid. If PAH8001EI-2G sensor is used, the data is received, while send command is invalid. The address parameters must be non-cacheable 4 bytes align and cannot be NULL. |
| hal_spi_master_status_t hal_spi_master_send_and_receive_dma_blocking | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_send_and_receive_config_t * | spi_send_and_receive_config | ||
| ) |
This function simultaneously sends and receives data in the DMA mode.
This function doesn't return until the transfer is complete. Normally this function is used in the scenario where the IRQ must be disabled.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | spi_send_and_receive_config | is the structure that contains data buffer and data size, please refer to hal_spi_master_send_and_receive_config_t , for more details. Check the SPI device's datasheet to determine if the data is sent or received. For example, if ADIS16375 is used in full duplex communication mode, the data is received, while send command is valid. If PAH8001EI-2G sensor is used, the data is received, while send command is invalid. The address parameters must be non-cacheable 4 bytes align and cannot be NULL. |
| hal_spi_master_status_t hal_spi_master_send_and_receive_polling | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_send_and_receive_config_t * | spi_send_and_receive_config | ||
| ) |
This function simultaneously sends and receives data in the FIFO mode.
This function doesn't return until the transfer is complete.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | spi_send_and_receive_config | is the structure that contains data buffer and data size, please refer to hal_spi_master_send_and_receive_config_t , for more details. Check the SPI device's datasheet to determine if the data is sent or received. For example, if ADIS16375 is used in full duplex communication mode, the data is received, while send command is valid. If PAH8001EI-2G sensor is used, the data is received, while send command is invalid. |
| hal_spi_master_status_t hal_spi_master_send_dma | ( | hal_spi_master_port_t | master_port, |
| uint8_t * | data, | ||
| uint32_t | size | ||
| ) |
This function is used to send data asynchronously with DMA mode.
This function returns immediately, before calling this function, user should call hal_spi_master_register_callback() to register a callback, then the callback will be called in the SPI ISR.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | data | is the data buffer to send, this parameter cannot be NULL, also the address must be a non-cacheable and 4 bytes align address. |
| [in] | size | is the number of bytes to send. |
| hal_spi_master_status_t hal_spi_master_send_dma_blocking | ( | hal_spi_master_port_t | master_port, |
| uint8_t * | data, | ||
| uint32_t | size | ||
| ) |
This function is used to send data synchronously with DMA mode.
This function doesn't return until the transfer is complete. Normally this function is used in the scenario where the IRQ must be disabled.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | data | is the data buffer to send, this parameter cannot be NULL, also the address must be a non-cacheable and 4 bytes align address. |
| [in] | size | is the number of bytes to send. |
| hal_spi_master_status_t hal_spi_master_send_polling | ( | hal_spi_master_port_t | master_port, |
| uint8_t * | data, | ||
| uint32_t | size | ||
| ) |
This function is used to send data synchronously with FIFO mode.
This function doesn't return until the transfer is complete.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | data | is the data buffer to send, this parameter cannot be NULL. |
| [in] | size | is the number of bytes to send. Note the user cannot send data size larger than HAL_SPI_MAXIMUM_POLLING_TRANSACTION_SIZE bytes. |
| hal_spi_master_status_t hal_spi_master_set_advanced_config | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_advanced_config_t * | advanced_config | ||
| ) |
SPI master advanced configuration function.
User can call this function to customize more settings for the SPI device operation. For more information about the settings, please refer to hal_spi_master_advanced_config_t.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | advanced_config | provides advanced configuration parameters for the SPI master. Details are described at hal_spi_master_advanced_config_t. |
| hal_spi_master_status_t hal_spi_master_set_chip_select_timing | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_chip_select_timing_t | chip_select_timing | ||
| ) |
This function is used to configure SPI master chip select timing parameter.
User can call this function to customize chip select signal timing if the default SPI master chip select signal timing doesn't match SPI device's requirement.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | chip_select_timing | is the parameter settings for chip select timing. |
| hal_spi_master_status_t hal_spi_master_set_deassert | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_deassert_t | deassert | ||
| ) |
SPI master chip select de-assertion mode configuration.
User can call this function to enable the deassert feature if the SPI device requires switching the chip select signal from invalid to valid after each byte transfer.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | deassert | is the parameter to set SPI master chip select signal behavior after sending one byte. |
| hal_spi_master_status_t hal_spi_master_set_macro_selection | ( | hal_spi_master_port_t | master_port, |
| hal_spi_master_macro_select_t | macro_select | ||
| ) |
SPI master macro group configuration.
If the GPIO selected doesn't belong to SPI pad macro group A, user should call this function to config it to the right pad macro.
| [in] | master_port | is the SPI master port number, the value is defined in hal_spi_master_port_t. |
| [in] | macro_select | is the parameter for macro group selection. |