![]() |
MT7697 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.
When the SPI master is operating on a high frequency clock and the hardware environment is not well designed, the SPI master may malfunction because of bad signal integrity. Use an oscilloscope to find out which pin requires an adjustment. Normally it'll be clock pin and data pin. Then call #hal_gpio_set_driving() to adjust the driving current of a specific SPI pin.
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_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_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_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... | |
Modules | |
| Define | |
| Enum | |
| Struct | |
| 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_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_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. |