embedded-software
reusable software modules for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SPI Module
Collaboration diagram for SPI Module:

Modules

 SPI Hardware Abstraction Layer for MSP432P401R
 

Data Structures

struct  spi_settings_t
 spi settings structure More...
 
struct  spi_transaction
 spi transaction structure More...
 

Macros

#define SPI_MAX_SIZE   8
 max length More...
 
#define SPI_MAX_TRANSACTIONS   4
 max queued transactions More...
 

Typedefs

typedef struct spi_settings_t spi_settings_t
 spi settings structure More...
 
typedef struct spi_transaction spi_transaction_t
 spi transaction typedef More...
 

Functions

void SPI_Init (spi_settings_t *spi_settings)
 initialize a SPI channel More...
 
int8_t SPI_Transact (spi_transaction_t *transaction)
 send a SPI transaction More...
 
void SPI_ISR (uint8_t channel)
 Interrupt service routine to be called from the HAL. More...
 
void hal_SPI_Init (spi_settings_t *settings)
 
void hal_SPI_Enable (uint8_t channel)
 
void hal_SPI_Disable (uint8_t channel)
 
uint8_t hal_SPI_SpaceAvailable (uint8_t channel)
 
uint8_t hal_SPI_DataAvailable (uint8_t channel)
 
void hal_SPI_ClearRxIF (uint8_t channel)
 
void hal_SPI_ClearTxIF (uint8_t channel)
 
void hal_SPI_EnableRxInterrupt (uint8_t channel)
 
void hal_SPI_EnableTxInterrupt (uint8_t channel)
 
void hal_SPI_DisableRxInterrupt (uint8_t channel)
 
void hal_SPI_DisableTxInterrupt (uint8_t channel)
 
uint8_t hal_SPI_TxIntStatus (uint8_t channel)
 
uint8_t hal_SPI_RxIntStatus (uint8_t channel)
 
uint8_t hal_SPI_IsTxIntEnabled (uint8_t channel)
 
uint8_t hal_SPI_RxByte (uint8_t channel)
 
void hal_SPI_TxByte (uint8_t channel, uint8_t b)
 
uint8_t hal_SPI_OverrunError (uint8_t channel)
 

Detailed Description

File: spi.h Author: Anthony Merlino

Transactional Master SPI module capable of bi-directional data transfer in a single transaction. Support blocking and non-blocking modes.

Currently supports 8-bit mode only.

Created on February 24, 2015, 11:03 PM

Macro Definition Documentation

#define SPI_MAX_SIZE   8

max length

#define SPI_MAX_TRANSACTIONS   4

max queued transactions

Typedef Documentation

spi settings structure

spi transaction typedef

Function Documentation

void hal_SPI_ClearRxIF ( uint8_t  channel)

Clear SPI receive interrupt flag

Parameters
channelSPI channel number

Here is the caller graph for this function:

void hal_SPI_ClearTxIF ( uint8_t  channel)

Clear SPI transmit interrupt flag

Parameters
channelSPI channel number

Here is the caller graph for this function:

uint8_t hal_SPI_DataAvailable ( uint8_t  channel)

Get data available status of SPI receive buffer

Parameters
channelSPI channel number
Returns
0 if no data is available in receive buffer, non-zero if data is available

Here is the caller graph for this function:

void hal_SPI_Disable ( uint8_t  channel)

Disable the SPI peripheral

Parameters
channelSPI channel number

Here is the caller graph for this function:

void hal_SPI_DisableRxInterrupt ( uint8_t  channel)

Disable SPI receive interrupts

Parameters
channelSPI channel number

Here is the caller graph for this function:

void hal_SPI_DisableTxInterrupt ( uint8_t  channel)

Disable SPI transmit interrupts

Parameters
channelSPI channel number

Here is the caller graph for this function:

void hal_SPI_Enable ( uint8_t  channel)

Enable the SPI peripheral

Parameters
channelSPI channel number

Here is the call graph for this function:

Here is the caller graph for this function:

void hal_SPI_EnableRxInterrupt ( uint8_t  channel)

Enable SPI receive interrupts

Parameters
channelSPI channel number

Here is the caller graph for this function:

void hal_SPI_EnableTxInterrupt ( uint8_t  channel)

Enable SPI transmit interrupts

Parameters
channelSPI channel number
void hal_SPI_Init ( spi_settings_t settings)

Initialize the SPI peripheral given the settings structure

Note: the developer of hal_spi can define hal_spi_settings_t to have whatever is required for implementing SPI on the target processor.

Parameters
settingspointer to spi_settings_structure.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t hal_SPI_IsTxIntEnabled ( uint8_t  channel)

Get enable status of SPI transmit interrupt

Parameters
channelSPI channel number
uint8_t hal_SPI_OverrunError ( uint8_t  channel)

Check if buffer overrrun has occured.

Here is the caller graph for this function:

uint8_t hal_SPI_RxByte ( uint8_t  channel)

Get byte from SPI receive buffer / register

Parameters
channelSPI channel number
Returns
data read from receive buffer / register

Here is the caller graph for this function:

uint8_t hal_SPI_RxIntStatus ( uint8_t  channel)

Get status of SPI receive interrupt flag

Parameters
channelSPI channel number

Here is the call graph for this function:

uint8_t hal_SPI_SpaceAvailable ( uint8_t  channel)

Get space available status of SPI transmit buffer

Parameters
channelSPI channel number
Returns
Return 0 if no space available in transmit buffer, non-zero if space is available

Here is the caller graph for this function:

void hal_SPI_TxByte ( uint8_t  channel,
uint8_t  b 
)

Write byte to SPI transmit buffer / register

Parameters
channelSPI channel number
byteto write
uint8_t hal_SPI_TxIntStatus ( uint8_t  channel)

Get status of SPI transmit interrupt flag

Parameters
channelSPI channel number

Here is the call graph for this function:

void SPI_Init ( spi_settings_t spi_settings)

initialize a SPI channel

To initialize a SPI module a spi_setting_t struct must be configured with the desired settings and then passed in by reference to this function.

Example usage:

spi_settings_t spi_settings;
spi_settings.channel = 1;
spi_settings.bit_rate = 100000;
// configure spi_settings.hal_settings as required for the target processor
spi_settings.mode = 0;
SPI_Init(&spi_settings);
Parameters
spi_settingspointer to spi_settings_t struct.

Here is the call graph for this function:

Here is the caller graph for this function:

void SPI_ISR ( uint8_t  channel)

Interrupt service routine to be called from the HAL.

Parameters
channelSPI channel

Here is the call graph for this function:

Here is the caller graph for this function:

int8_t SPI_Transact ( spi_transaction_t transaction)

send a SPI transaction

When configuring the SPI transaction the user must specify:

  • transaction.flags.channel The SPI channel to use
  • transaction.flags.blocking Whether or not to use blocking mode
  • transaction.cs_control A pointer to a chip select function
  • transaction.writeLength How many bytes to write
  • transaction.readDelay How many bytes to delay before saving read data
  • transaction.readLength How many bytes to read
  • transaction.data Initialize data in array to write (if reading and writing simultaneously then write data will be overwritten with read data after it is written).

Usage Example:

void Channel1ChipSelect(uint8_t cs) {
// assuming CS_PIN_1 is defined as an output register somewhere
CS_PIN_1 = cs ? 1 : 0;
}
//...
// write two bytes, receive the second byte through the fifth byte
spi_transaction_t transaction;
transaction.flags.channel = 1;
transaction.flags.blocking = 1;
transaction.cs_control = Channel1ChipSelect;
transaction.writeLength = 2;
transaction.readLength = 4;
transaction.readDelay = 1;
transaction.data[0] = 0x20;
transaction.data[1] = 0x85;
SPI_Transact(&transaction);
// at this point transaction.data[1] through transaction.data[4] contain the data read
Parameters
transactionpointer to spi_transaction_t structure
Warning
Not interrupt safe

Here is the call graph for this function:

Here is the caller graph for this function: