Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
fsl_spi_hal.h File Reference
#include "fsl_device_registers.h"
#include <stdint.h>
#include <stdbool.h>

Enumerations

enum  spi_status_t {
  kStatus_SPI_Success = 0,
  kStatus_SPI_SlaveTxUnderrun,
  kStatus_SPI_SlaveRxOverrun,
  kStatus_SPI_Timeout,
  kStatus_SPI_Busy,
  kStatus_SPI_NoTransferInProgress,
  kStatus_SPI_OutOfRange,
  kStatus_SPI_TxBufferNotEmpty,
  kStatus_SPI_InvalidParameter,
  kStatus_SPI_NonInit,
  kStatus_SPI_AlreadyInitialized,
  kStatus_SPI_DMAChannelInvalid,
  kStatus_SPI_Error
}
 Error codes for the SPI driver. More...
 
enum  spi_master_slave_mode_t {
  kSpiMaster = 1,
  kSpiSlave = 0
}
 SPI master or slave configuration. More...
 
enum  spi_clock_polarity_t {
  kSpiClockPolarity_ActiveHigh = 0,
  kSpiClockPolarity_ActiveLow = 1
}
 SPI clock polarity configuration. More...
 
enum  spi_clock_phase_t {
  kSpiClockPhase_FirstEdge = 0,
  kSpiClockPhase_SecondEdge = 1
}
 SPI clock phase configuration. More...
 
enum  spi_shift_direction_t {
  kSpiMsbFirst = 0,
  kSpiLsbFirst = 1
}
 SPI data shifter direction options. More...
 
enum  spi_ss_output_mode_t {
  kSpiSlaveSelect_AsGpio = 0,
  kSpiSlaveSelect_FaultInput = 2,
  kSpiSlaveSelect_AutomaticOutput = 3
}
 SPI slave select output mode options. More...
 
enum  spi_pin_mode_t {
  kSpiPinMode_Normal = 0,
  kSpiPinMode_Input = 1,
  kSpiPinMode_Output = 3
}
 SPI pin mode options. More...
 
enum  spi_data_bitcount_mode_t {
  kSpi8BitMode = 0,
  kSpi16BitMode = 1
}
 SPI data length mode options. More...
 
enum  spi_interrupt_source_t {
  kSpiRxFullAndModfInt = 1,
  kSpiTxEmptyInt = 2,
  kSpiMatchInt = 3
}
 SPI interrupt sources. More...
 
enum  spi_int_status_flag_t {
  kSpiRxBufferFullFlag = SPI_S_SPRF_SHIFT,
  kSpiMatchFlag = SPI_S_SPMF_SHIFT,
  kSpiTxBufferEmptyFlag = SPI_S_SPTEF_SHIFT,
  kSpiModeFaultFlag = SPI_S_MODF_SHIFT
}
 SPI interrupt status flags. More...
 
enum  spi_fifo_interrupt_source_t {
  kSpiRxFifoNearFullInt = 1,
  kSpiTxFifoNearEmptyInt = 2
}
 SPI FIFO interrupt sources. More...
 
enum  spi_w1c_interrupt_t {
  kSpiRxFifoFullClearInt = 0,
  kSpiTxFifoEmptyClearInt = 1,
  kSpiRxNearFullClearInt = 2,
  kSpiTxNearEmptyClearInt = 3
}
 SPI FIFO write-1-to-clear interrupt flags. More...
 
enum  spi_txfifo_watermark_t {
  kSpiTxFifoOneFourthEmpty = 0,
  kSpiTxFifoOneHalfEmpty = 1
}
 SPI TX FIFO watermark settings. More...
 
enum  spi_rxfifo_watermark_t {
  kSpiRxFifoThreeFourthsFull = 0,
  kSpiRxFifoOneHalfFull = 1
}
 SPI RX FIFO watermark settings. More...
 
enum  spi_fifo_status_flag_t {
  kSpiRxFifoEmpty = 0,
  kSpiTxFifoFull = 1,
  kSpiTxNearEmpty = 2,
  kSpiRxNearFull = 3
}
 SPI status flags. More...
 
enum  spi_fifo_error_flag_t {
  kSpiNoFifoError = 0,
  kSpiRxfof = 1,
  kSpiTxfof = 2,
  kSpiRxfofTxfof = 3,
  kSpiRxferr = 4,
  kSpiRxfofRxferr = 5,
  kSpiTxfofRxferr = 6,
  kSpiRxfofTxfofRxferr = 7,
  kSpiTxferr = 8,
  kSpiRxfofTxferr = 9,
  kSpiTxfofTxferr = 10,
  kSpiRxfofTxfofTxferr = 11,
  kSpiRxferrTxferr = 12,
  kSpiRxfofRxferrTxferr = 13,
  kSpiTxfofRxferrTxferr = 14,
  kSpiRxfofTxfofRxferrTxferr =15
}
 SPI error flags. More...
 

Functions

Configuration
void SPI_HAL_Init (SPI_Type *base)
 Restores the SPI to the 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...