AceSPI
0.2.0
Unified interface for selecting hardware or software SPI implementations on Arduino platforms
|
Hardware SPI interface to talk to SPI peripherals. More...
#include <HardSpiInterface.h>
Public Member Functions | |
HardSpiInterface (T_SPI &spi, uint8_t latchPin) | |
Constructor. More... | |
void | begin () const |
Initialize the HardSpiInterface. More... | |
void | end () const |
Clean up the object. | |
void | send8 (uint8_t value) const |
Send 8 bits, including latching LOW and HIGH. | |
void | send16 (uint16_t value) const |
Send 16 bits, including latching LOW and HIGH. | |
void | send16 (uint8_t msb, uint8_t lsb) const |
Send two 8-bit bytes as a single 16-bit stream, including latching LOW and HIGH. | |
HardSpiInterface (const HardSpiInterface &)=default | |
HardSpiInterface & | operator= (const HardSpiInterface &)=default |
Hardware SPI interface to talk to SPI peripherals.
It was initially created to communicate with the 74HC595 Shift Register chip, then verified to work with the MAX7219 LED controller chip. This is currently not meant to be general-purpose SPI interface. In particular, it supports only SPI MODE0, and MSBFIRST configurations.
For different SPI configurations, it is probably easiest to just copy this file, make the necessary changes, then substitute the new class in places where this class is used. The maximum speed of MAX7219 is 16MHz so this class sets the default SPI speed to 8MHz.
The ESP32 has 2 user-accessible SPI buses (HSPI and VSPI), and so does the STM32F1 (SPI1 and SPI2). Usually, the predefined SPI instance is used, but a user-defined secondary SPI instance can be passed into the constructor.
T_SPI | the class of the hardware SPI instance, usually SPIClass |
T_CLOCK_SPEED | the SPI clock speed, default 8000000 (8 MHz) |
Definition at line 57 of file HardSpiInterface.h.
|
inlineexplicit |
Constructor.
spi | instance of the T_SPI class. If the pre-installed <SPI.h> is used, T_SPI is SPIClass and spi will be the pre-defined SPI object. |
latchPin | the pin that controls the CS/SS pin of the slave device |
Definition at line 82 of file HardSpiInterface.h.
|
inline |
Initialize the HardSpiInterface.
The hardware SPI object must be initialized using SPI.begin()
as well.
Definition at line 91 of file HardSpiInterface.h.