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
#define SPI_MAX_TRANSACTIONS 4 |
void hal_SPI_ClearRxIF |
( |
uint8_t |
channel | ) |
|
Clear SPI receive interrupt flag
- Parameters
-
channel | SPI channel number |
void hal_SPI_ClearTxIF |
( |
uint8_t |
channel | ) |
|
Clear SPI transmit interrupt flag
- Parameters
-
channel | SPI channel number |
uint8_t hal_SPI_DataAvailable |
( |
uint8_t |
channel | ) |
|
Get data available status of SPI receive buffer
- Parameters
-
channel | SPI channel number |
- Returns
- 0 if no data is available in receive buffer, non-zero if data is available
void hal_SPI_Disable |
( |
uint8_t |
channel | ) |
|
Disable the SPI peripheral
- Parameters
-
channel | SPI channel number |
void hal_SPI_DisableRxInterrupt |
( |
uint8_t |
channel | ) |
|
Disable SPI receive interrupts
- Parameters
-
channel | SPI channel number |
void hal_SPI_DisableTxInterrupt |
( |
uint8_t |
channel | ) |
|
Disable SPI transmit interrupts
- Parameters
-
channel | SPI channel number |
void hal_SPI_Enable |
( |
uint8_t |
channel | ) |
|
Enable the SPI peripheral
- Parameters
-
channel | SPI channel number |
void hal_SPI_EnableRxInterrupt |
( |
uint8_t |
channel | ) |
|
Enable SPI receive interrupts
- Parameters
-
channel | SPI channel number |
void hal_SPI_EnableTxInterrupt |
( |
uint8_t |
channel | ) |
|
Enable SPI transmit interrupts
- Parameters
-
channel | SPI channel number |
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
-
settings | pointer to spi_settings_structure. |
uint8_t hal_SPI_IsTxIntEnabled |
( |
uint8_t |
channel | ) |
|
Get enable status of SPI transmit interrupt
- Parameters
-
channel | SPI channel number |
uint8_t hal_SPI_OverrunError |
( |
uint8_t |
channel | ) |
|
Check if buffer overrrun has occured.
uint8_t hal_SPI_RxByte |
( |
uint8_t |
channel | ) |
|
Get byte from SPI receive buffer / register
- Parameters
-
channel | SPI channel number |
- Returns
- data read from receive buffer / register
uint8_t hal_SPI_RxIntStatus |
( |
uint8_t |
channel | ) |
|
Get status of SPI receive interrupt flag
- Parameters
-
channel | SPI channel number |
uint8_t hal_SPI_SpaceAvailable |
( |
uint8_t |
channel | ) |
|
Get space available status of SPI transmit buffer
- Parameters
-
channel | SPI channel number |
- Returns
- Return 0 if no space available in transmit buffer, non-zero if space is available
void hal_SPI_TxByte |
( |
uint8_t |
channel, |
|
|
uint8_t |
b |
|
) |
| |
Write byte to SPI transmit buffer / register
- Parameters
-
channel | SPI channel number |
byte | to write |
uint8_t hal_SPI_TxIntStatus |
( |
uint8_t |
channel | ) |
|
Get status of SPI transmit interrupt flag
- Parameters
-
channel | SPI channel number |
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:
- Parameters
-
void SPI_ISR |
( |
uint8_t |
channel | ) |
|
Interrupt service routine to be called from the HAL.
- Parameters
-
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) {
CS_PIN_1 = cs ? 1 : 0;
}
transaction.
data[0] = 0x20;
transaction.
data[1] = 0x85;
- Parameters
-
transaction | pointer to spi_transaction_t structure |
- Warning
- Not interrupt safe