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.
spihelper.h | Helper functions and macros for communication via the ATmega’s SPI hardware. |
Functions | |
spihelper_mstr_init | Configures the SPI module for Master mode. |
spihelper_init | 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. |
spihelper_shutdown | 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.
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.
ss_b | Bit flags specifying the pins in I/O port B that should be readied for use as SPI Slave Select output pins. |
ss_c | Bit flags specifying the pins in I/O port C that should be readied for use as SPI Slave Select output pins. |
ss_d | Bit flags specifying the pins in I/O port D that should be readied for use as SPI Slave Select output pins. |
ctrl | Value 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. |
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.
ctrl | Value 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. |
Configures the SPI module for Master mode.
void spihelper_mstr_init( uint8_t ss_b, uint8_t ss_c, uint8_t ss_d, 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_init( uint8_t ctrl )
Disables the SPI module.
void spihelper_shutdown( void )