spihelper.h

Helper functions and macros for communication via the ATmega’s SPI hardware.

CAUTION (ATmegaU) : Port C is very small on the ATmegaU (only two pins), so if LIBAVR_ATMEGA_U is defined, the port called “C” in this module is actually hardware port F.

Summary
spihelper.hHelper functions and macros for communication via the ATmega’s SPI hardware.
Functions
spihelper_mstr_initConfigures the SPI module for Master mode.
spihelper_initConfigures the SPI module for either Master or Slave mode, depending on the value of the Master/Slave Select (MSTR) bit in the ctrl argument.
spihelper_shutdownDisables the SPI module.

Functions

spihelper_mstr_init

void spihelper_mstr_init(uint8_t ss_b,
uint8_t ss_c,
uint8_t ss_d,
uint8_t ctrl)

Configures the SPI module for Master mode.

I/O pins that are marked as Slave Select output pins via ss_x parameters will be configured as outputs and driven high by this function.  The output high / pull-up enable state will be set before the data direction is set to output.

NOTE: This function invokes spihelper_init internally.

Parameters

ss_bBit flags specifying the pins in I/O port B that should be readied for use as SPI Slave Select output pins.
ss_cBit flags specifying the pins in I/O port C that should be readied for use as SPI Slave Select output pins.
ss_dBit flags specifying the pins in I/O port D that should be readied for use as SPI Slave Select output pins.
ctrlValue to assign to the SPI Control Register (SPCR).  When this function returns, the SPI Enable (SPE) bit in the SPCR will always be set to one, regardless of its value in the ctrl parameter.  The Master/Slave Select (MSTR) bit will likewise always be set to one.

spihelper_init

void spihelper_init(uint8_t ctrl)

Configures the SPI module for either Master or Slave mode, depending on the value of the Master/Slave Select (MSTR) bit in the ctrl argument.

Parameters

ctrlValue to assign to the SPI Control Register (SPCR).  When this function returns, the SPI Enable (SPE) bit in the SPCR will always be set to one, regardless of its value in the ctrl parameter.  If the MSTR bit in this parameter is set to one, the SPI module will be configured for Master mode, otherwise, it will be configured for Slave mode.

spihelper_shutdown

void spihelper_shutdown(void)

Disables the SPI module.

void spihelper_mstr_init(uint8_t ss_b,
uint8_t ss_c,
uint8_t ss_d,
uint8_t ctrl)
Configures the SPI module for Master mode.
void spihelper_init(uint8_t ctrl)
Configures the SPI module for either Master or Slave mode, depending on the value of the Master/Slave Select (MSTR) bit in the ctrl argument.
void spihelper_shutdown(void)
Disables the SPI module.
Close