![]() |
Kinetis SDK v.1.2 API Reference Manual
Rev. 0
Freescale Semiconductor, Inc.
|
This section describes the programming interface of the SPI HAL driver.
Files | |
file | fsl_spi_hal.h |
Configuration | |
void | SPI_HAL_Init (SPI_Type *base) |
Restores the SPI to reset configuration. More... | |
static void | SPI_HAL_Enable (SPI_Type *base) |
Enables the SPI peripheral. More... | |
static void | SPI_HAL_Disable (SPI_Type *base) |
Disables the SPI peripheral. More... | |
uint32_t | SPI_HAL_SetBaud (SPI_Type *base, uint32_t bitsPerSec, uint32_t sourceClockInHz) |
Sets the SPI baud rate in bits per second. More... | |
static void | SPI_HAL_SetBaudDivisors (SPI_Type *base, uint32_t prescaleDivisor, uint32_t rateDivisor) |
Configures the baud rate divisors manually. More... | |
static void | SPI_HAL_SetMasterSlave (SPI_Type *base, spi_master_slave_mode_t mode) |
Configures the SPI for master or slave. More... | |
static bool | SPI_HAL_IsMaster (SPI_Type *base) |
Returns whether the SPI module is in master mode. More... | |
void | SPI_HAL_SetSlaveSelectOutputMode (SPI_Type *base, spi_ss_output_mode_t mode) |
Sets how the slave select output operates. More... | |
void | SPI_HAL_SetDataFormat (SPI_Type *base, spi_clock_polarity_t polarity, spi_clock_phase_t phase, spi_shift_direction_t direction) |
Sets the polarity, phase, and shift direction. More... | |
static uint32_t | SPI_HAL_GetDataRegAddr (SPI_Type *base) |
Gets the SPI data register address for DMA operation. More... | |
void | SPI_HAL_SetPinMode (SPI_Type *base, spi_pin_mode_t mode) |
Sets the SPI pin mode. More... | |
Interrupts | |
void | SPI_HAL_SetIntMode (SPI_Type *base, spi_interrupt_source_t interrupt, bool enable) |
Enables or disables the SPI interrupts. More... | |
static void | SPI_HAL_SetReceiveAndFaultIntCmd (SPI_Type *base, bool enable) |
Enables or disables the SPI receive buffer/FIFO full and mode fault interrupt. More... | |
static void | SPI_HAL_SetTransmitIntCmd (SPI_Type *base, bool enable) |
Enables or disables the SPI transmit buffer/FIFO empty interrupt. More... | |
static void | SPI_HAL_SetMatchIntCmd (SPI_Type *base, bool enable) |
Enables or disables the SPI match interrupt. More... | |
Status | |
static bool | SPI_HAL_GetIntStatusFlag (SPI_Type *base, spi_int_status_flag_t flag) |
Gets the SPI interrupt status flag state. More... | |
static bool | SPI_HAL_IsReadBuffFullPending (SPI_Type *base) |
Checks whether the read buffer/FIFO is full. More... | |
static bool | SPI_HAL_IsTxBuffEmptyPending (SPI_Type *base) |
Checks whether the transmit buffer/FIFO is empty. More... | |
static bool | SPI_HAL_IsModeFaultPending (SPI_Type *base) |
Checks whether a mode fault occurred. More... | |
void | SPI_HAL_ClearModeFaultFlag (SPI_Type *base) |
Clears the mode fault flag. More... | |
static bool | SPI_HAL_IsMatchPending (SPI_Type *base) |
Checks whether the data received matches the previously-set match value. More... | |
void | SPI_HAL_ClearMatchFlag (SPI_Type *base) |
Clears the match flag. More... | |
Data transfer | |
static uint8_t | SPI_HAL_ReadData (SPI_Type *base) |
Reads a byte from the data buffer. More... | |
static void | SPI_HAL_WriteData (SPI_Type *base, uint8_t data) |
Writes a byte into the data buffer. More... | |
void | SPI_HAL_WriteDataBlocking (SPI_Type *base, uint8_t data) |
Writes a byte into the data buffer and waits till complete to return. More... | |
Match byte | |
static void | SPI_HAL_SetMatchValue (SPI_Type *base, uint8_t matchByte) |
Sets the value which triggers the match interrupt. More... | |
enum spi_status_t |
enum spi_clock_polarity_t |
enum spi_clock_phase_t |
enum spi_ss_output_mode_t |
enum spi_pin_mode_t |
enum spi_w1c_interrupt_t |
void SPI_HAL_Init | ( | SPI_Type * | base | ) |
This function basically resets all of the SPI registers to their default setting including disabling the module.
base | Module base pointer of type SPI_Type. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
uint32_t SPI_HAL_SetBaud | ( | SPI_Type * | base, |
uint32_t | bitsPerSec, | ||
uint32_t | sourceClockInHz | ||
) |
This function takes in the desired bitsPerSec (baud rate) and calculates the nearest possible baud rate without exceeding the desired baud rate unless the baud rate requested is less than the absolute minimum in which case the minimum baud rate will be returned. The returned baud rate is in bits-per-second. It requires that the caller also provide the frequency of the module source clock (in Hertz).
base | Module base pointer of type SPI_Type. |
bitsPerSec | The desired baud rate in bits per second. |
sourceClockInHz | Module source input clock in Hertz. |
|
inlinestatic |
This function allows the caller to manually set the baud rate divisors in the event that these dividers are known and the caller does not wish to call the SPI_HAL_SetBaudRate function.
base | Module base pointer of type SPI_Type. |
prescaleDivisor | baud rate prescale divisor setting. |
rateDivisor | baud rate divisor setting. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
mode | Mode setting (master or slave) of type dspi_master_slave_mode_t. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
void SPI_HAL_SetSlaveSelectOutputMode | ( | SPI_Type * | base, |
spi_ss_output_mode_t | mode | ||
) |
This function allows the user to configure the slave select in one of the three operational modes: as GPIO, as a fault input, or as an automatic output for standard SPI modes.
base | Module base pointer of type SPI_Type. |
mode | Selection input of one of three modes of type spi_ss_output_mode_t. |
void SPI_HAL_SetDataFormat | ( | SPI_Type * | base, |
spi_clock_polarity_t | polarity, | ||
spi_clock_phase_t | phase, | ||
spi_shift_direction_t | direction | ||
) |
This function configures the clock polarity, clock phase, and data shift direction.
base | Module base pointer of type SPI_Type. |
polarity | Clock polarity setting of type spi_clock_polarity_t. |
phase | Clock phase setting of type spi_clock_phase_t. |
direction | Data shift direction (MSB or LSB) of type spi_shift_direction_t. |
|
inlinestatic |
This function gets the SPI data register address as this value is needed for DMA operation.
base | Module base pointer of type SPI_Type. |
void SPI_HAL_SetPinMode | ( | SPI_Type * | base, |
spi_pin_mode_t | mode | ||
) |
This function configures the SPI data pins to one of three modes (of type spi_pin_mode_t): Single direction mode: MOSI and MISO pins operate in normal, single direction mode. Bidirectional mode: Master: MOSI configured as input, Slave: MISO configured as input. Bidirectional mode: Master: MOSI configured as output, Slave: MISO configured as output.
base | Module base pointer of type SPI_Type. |
mode | Operational of SPI pins of type spi_pin_mode_t. |
void SPI_HAL_SetIntMode | ( | SPI_Type * | base, |
spi_interrupt_source_t | interrupt, | ||
bool | enable | ||
) |
This function enables or disables the SPI receive buffer (or FIFO if the module supports a FIFO) full and mode fault interrupt SPI transmit buffer (or FIFO if the module supports a FIFO) empty interrupt SPI match interrupt
Example, to set the receive and mode fault interrupt: SPI_HAL_SetIntMode(base, kSpiRxFullAndModfInt, true);
base | Module base pointer of type SPI_Type. |
interrupt | SPI interrupt source to configure of type spi_interrupt_source_t. |
enable | Enable (true) or disable (false) the receive buffer full and mode fault interrupt. |
|
inlinestatic |
This function enables or disables the SPI receive buffer (or FIFO if the module supports a FIFO) full and mode fault interrupt.
base | Module base pointer of type SPI_Type. |
enable | Enable (true) or disable (false) the receive buffer full and mode fault interrupt. |
|
inlinestatic |
This function enables or disables the SPI transmit buffer (or FIFO if the module supports a FIFO) empty interrupt.
base | Module base pointer of type SPI_Type. |
enable | Enable (true) or disable (false) the transmit buffer empty interrupt. |
|
inlinestatic |
This function enables or disables the SPI match interrupt.
base | Module base pointer of type SPI_Type. |
enable | Enable (true) or disable (false) the match interrupt. |
|
inlinestatic |
This function returns the state (set or cleared) of the SPI interrupt status flag.
base | Module base pointer of type SPI_Type. |
flag | The requested interrupt status flag of type spi_int_status_flag_t. |
|
inlinestatic |
The read buffer (or FIFO if the module supports a FIFO) full flag is only cleared by reading it when it is set, then reading the data register by calling the SPI_HAL_ReadData(). This example code demonstrates how to check the flag, read data, and clear the flag.
base | Module base pointer of type SPI_Type. |
|
inlinestatic |
To clear the transmit buffer (or FIFO if the module supports a FIFO) empty flag, you must first read the flag when it is set. Then write a new data value into the transmit buffer with a call to the SPI_HAL_WriteData(). The example code shows how to do this.
base | Module base pointer of type SPI_Type. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
void SPI_HAL_ClearModeFaultFlag | ( | SPI_Type * | base | ) |
base | Module base pointer of type SPI_Type |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
void SPI_HAL_ClearMatchFlag | ( | SPI_Type * | base | ) |
base | Module base pointer of type SPI_Type. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
data | The data to send. |
void SPI_HAL_WriteDataBlocking | ( | SPI_Type * | base, |
uint8_t | data | ||
) |
This function writes data to the SPI data register and waits until the TX is empty to return.
base | Module base pointer of type SPI_Type. |
data | The data to send. |
|
inlinestatic |
base | Module base pointer of type SPI_Type. |
matchByte | The value which triggers the match interrupt. |