AceSPI  0.3
Unified interface for selecting hardware or software SPI implementations on Arduino platforms
Public Member Functions | List of all members
ace_spi::HardSpiInterface< T_SPI, T_CLOCK_SPEED > Class Template Reference

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 beginTransaction () const
 Begin SPI transaction. More...
 
void endTransaction () const
 End SPI transaction. More...
 
void transfer (uint8_t value) const
 Transfer 8 bits.
 
void transfer16 (uint16_t value) const
 Transfer 16 bits.
 
void send8 (uint8_t value) const
 Convenience method to send 8 bits a single transaction.
 
void send16 (uint16_t value) const
 Convenience method to send 16 bits a single transaction.
 
void send16 (uint8_t msb, uint8_t lsb) const
 Convenience method to send 16 bits a single transaction.
 
 HardSpiInterface (const HardSpiInterface &)=default
 
HardSpiInterfaceoperator= (const HardSpiInterface &)=default
 

Detailed Description

template<typename T_SPI, uint32_t T_CLOCK_SPEED = 8000000>
class ace_spi::HardSpiInterface< T_SPI, T_CLOCK_SPEED >

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.

Template Parameters
T_SPIthe class of the hardware SPI instance, usually SPIClass
T_CLOCK_SPEEDthe SPI clock speed, default 8000000 (8 MHz)

Definition at line 57 of file HardSpiInterface.h.

Constructor & Destructor Documentation

◆ HardSpiInterface()

template<typename T_SPI , uint32_t T_CLOCK_SPEED = 8000000>
ace_spi::HardSpiInterface< T_SPI, T_CLOCK_SPEED >::HardSpiInterface ( T_SPI &  spi,
uint8_t  latchPin 
)
inlineexplicit

Constructor.

Parameters
spiinstance 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.
latchPinthe pin that controls the CS/SS pin of the slave device

Definition at line 82 of file HardSpiInterface.h.

Member Function Documentation

◆ begin()

template<typename T_SPI , uint32_t T_CLOCK_SPEED = 8000000>
void ace_spi::HardSpiInterface< T_SPI, T_CLOCK_SPEED >::begin ( ) const
inline

Initialize the HardSpiInterface.

The hardware SPI object must be initialized using SPI.begin() as well.

Definition at line 91 of file HardSpiInterface.h.

◆ beginTransaction()

template<typename T_SPI , uint32_t T_CLOCK_SPEED = 8000000>
void ace_spi::HardSpiInterface< T_SPI, T_CLOCK_SPEED >::beginTransaction ( ) const
inline

Begin SPI transaction.

Pull latch LOW.

Definition at line 112 of file HardSpiInterface.h.

◆ endTransaction()

template<typename T_SPI , uint32_t T_CLOCK_SPEED = 8000000>
void ace_spi::HardSpiInterface< T_SPI, T_CLOCK_SPEED >::endTransaction ( ) const
inline

End SPI transaction.

Pull latch HIGH.

Definition at line 118 of file HardSpiInterface.h.


The documentation for this class was generated from the following file: