SPI Peripheral Module Class. More...
#include <dspi.h>
Public Member Functions | |
SPIModule (uint8_t SPIModule) | |
Create a SPI object. More... | |
SPIModule (uint8_t SPIModule, uint32_t baudRateInBps, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x00, uint8_t chipSelectPolarity=0x0F, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0) | |
Create a SPI object and Initialize with parameters. More... | |
uint8_t | Init (uint32_t baudRateInBps=2000000, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x00, uint8_t chipSelectPolarity=0x0F, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0) |
Initialize an existing SPI object. More... | |
uint32_t | SetBusSpeed (uint32_t maxSpeed) |
Set the SPI bus speed Will attempt to set the desired bus speed. It may be different based on the available system characteristics. More... | |
uint8_t | Start (uint8_t *transmitBufferPtr, volatile uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST) |
Start a SPI transfer. More... | |
uint8_t | Tx (uint8_t *transmitBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST) |
Convenience function for unidirectional transmit. More... | |
uint8_t | Rx (uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST) |
Convenience function for unidirectional receive. More... | |
bool | RegisterSem (OS_SEM *finishedSem) |
Register a semaphore for the SPI module. More... | |
bool | ClrSem () |
Clear a semaphore registration. More... | |
OS_SEM * | GetSem () |
Obtain a pointer to the SPI finished semaphore. More... | |
bool | Done () |
Function to check SPI status. More... | |
uint32_t | GetActualBaudrate () |
Returns the active baud rate. More... | |
bool | SetCS (uint8_t CS) |
Set the chip select configuration for the SPI object's bus transactions. More... | |
Static Public Member Functions | |
static BOOL | Done (uint8_t SPIModule) |
Static function to check SPI status. More... | |
SPI Peripheral Module Class.
Class definition for SPI module objects
SPIModule::SPIModule | ( | uint8_t | SPIModule | ) |
SPIModule::SPIModule | ( | uint8_t | SPIModule, |
uint32_t | baudRateInBps, | ||
uint8_t | transferSizeInBits = 8 , |
||
uint8_t | peripheralChipSelects = 0x00 , |
||
uint8_t | chipSelectPolarity = 0x0F , |
||
uint8_t | clockPolarity = 0 , |
||
uint8_t | clockPhase = 1 , |
||
BOOL | doutHiz = TRUE , |
||
uint8_t | csToClockDelay = 0 , |
||
uint8_t | delayAfterTransfer = 0 |
||
) |
Create a SPI object and Initialize with parameters.
Creaets a SPI object and initializes the SPI module. You do not need to call the Init() member function.
SPIModule | SPI module number (0 or 1) |
baudRateInBps | Maximum baud rate requested |
transferSizeInBits | Number of bits per transfer: 8, 16 or 32 |
peripheralChipSelects | SPI chip selects to use for transfer |
chipSelectPolarity | 0 = inactive logic level low, 1 = high |
clockPolarity | 0 = inactive logic level low, 1 = high |
clockPhase | 0 = data captured leading edge clock, changed following edge. 1 = data changed leading edge clock, captured following edge. |
doutHiz | Data output high impedance between transfers |
csToClockDelay | Delay from chip select to valid clock (default is 0) |
delayAfterTransfer | Chip select mode DspiChipSelectMode |
|
inline |
Clear a semaphore registration.
|
inline |
Function to check SPI status.
Called as a class method on a specific SPI object. For example: MySpi.Done()
|
static |
Static function to check SPI status.
Is called as a class wide static method. For example: SPIModule::Done(0)
SPIModule | The SPI module to check, 0, 1 or 2 |
|
inline |
Returns the active baud rate.
The baud rate will be set to the value specified when the SPI module is initialized. If that value is not possible, the next lowest baud rate will be chosen.
|
inline |
Obtain a pointer to the SPI finished semaphore.
uint8_t SPIModule::Init | ( | uint32_t | baudRateInBps = 2000000 , |
uint8_t | transferSizeInBits = 8 , |
||
uint8_t | peripheralChipSelects = 0x00 , |
||
uint8_t | chipSelectPolarity = 0x0F , |
||
uint8_t | clockPolarity = 0 , |
||
uint8_t | clockPhase = 1 , |
||
BOOL | doutHiz = TRUE , |
||
uint8_t | csToClockDelay = 0 , |
||
uint8_t | delayAfterTransfer = 0 |
||
) |
Initialize an existing SPI object.
SPIModule | SPI module number (0 or 1) |
baudRateInBps | Maximum baud rate requested |
transferSizeInBits | Number of bits per transfer: 8, 16 or 32 |
peripheralChipSelects | SPI chip selects to use for transfer |
chipSelectPolarity | 0 = inactive logic level low, 1 = high |
clockPolarity | 0 = inactive logic level low, 1 = high |
clockPhase | 0 = data captured leading edge clock, changed following edge. 1 = data changed leading edge clock, captured following edge. |
doutHiz | Data output high impedance between transfers |
csToClockDelay | Delay from chip select to valid clock (default is 0) |
delayAfterTransfer | Chip select mode DspiChipSelectMode |
bool SPIModule::RegisterSem | ( | OS_SEM * | finishedSem | ) |
Register a semaphore for the SPI module.
The SPI module will post to this semaphore when a transaction is complete
finishedSem | Pointer to the semaphore |
|
inline |
Convenience function for unidirectional receive.
transmitBufferPtr | Pointer to the buffer containing the data to transmit |
byteCount | Number of bytes to transmit |
csReturnToInactive | Chip select state |
uint32_t SPIModule::SetBusSpeed | ( | uint32_t | maxSpeed | ) |
Set the SPI bus speed Will attempt to set the desired bus speed. It may be different based on the available system characteristics.
maxSpeed | The maximum desired bus speed |
|
inline |
Set the chip select configuration for the SPI object's bus transactions.
Chip | select to set, 0 - 3. |
uint8_t SPIModule::Start | ( | uint8_t * | transmitBufferPtr, |
volatile uint8_t * | receiveBufferPtr, | ||
uint32_t | byteCount, | ||
int | csReturnToInactive = DEASSERT_AFTER_LAST |
||
) |
Start a SPI transfer.
transmitBufferPtr | Pointer to the buffer containing the data to transmit |
receiveBufferPtr | Pointer to the buffer to store the received data |
byteCount | Number of bytes to transmit |
csReturnToInactive | Chip select state |
|
inline |
Convenience function for unidirectional transmit.
transmitBufferPtr | Pointer to the buffer containing the data to transmit |
byteCount | Number of bytes to transmit |
csReturnToInactive | Chip select state |