HWA
Bare metal programming with style
Class _spia: Serial Peripheral Interface

A class _spia object is a Serial Peripheral Interface. It has the following relatives:

It is used by:

Interrupts

Class _spia objects can trigger the following IRQs:

Actions

configure:

Note 1 When configured in master or slave mode, the SPI automatically configures its related I/O pins as inputs or outputs according to the mode.

Note 2 In master mode, if the SS pin is configured as an input, it must be held high. Otherwise the SPI will be automatically turned into slave mode by hardware as soon as the SS pin goes low.

hwa( configure, spi0,
function, master
| slave
| off,
clock, ioclk / ( 2 // Clock frequency
| 4
| 8
| 16
| 32
| 64
| 128 ),
[ mode, 0 | 1 | 2 | 3, ]
[ idle_state, low // State of SCK when idle
| high,
sampling_edge, falling // Sampling clock edge
| rising, ]
[ data_order, lsb_first
| msb_first ] );

read:

hw( read, spi0 );

write:

hw(_write, spi0, value );

turn: when the SPI is turned on, it takes control of the MOSI and MISO pins.

hw( turn, spi0, on | off );
hwa( turn, spi0, on | off );

stat: returns the collision flag:

hw_stat_t( spi0 ) st ; // Create a structure to receive the counter status
st = hw( stat, spi0 ); // Copy the SPI status into the structure
if ( st.collision ) // Process the collision flag
n_collisions++ ;

Reading the "transfer complete" flag:

if ( hw( read, (spi0,irq) ) ) // Read "transfer complete" IRQ flag
hw( disable, (spi0,irq) ); // Disable transfer complete IRQs

The "transfer complete" flag is cleared by hardware when the corresponding ISR is executed. It is also cleared when the SPI is read or written after the flag has been read:

if ( hw( read, (spi0,irq) ) ) // Read transfer complete IRQ flag
data = hw( read, spi0 ); // Read data and clear transfer complete IRQ flag

Registers

Class _spia objects hold the following hardware registers:

that hold the following logical registers:

hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523
hw_stat_t
#define hw_stat_t(object)
Declares the appropriate structure that holds the status of an object.
Definition: hwa_macros.h:711