rcc 1.0
RCC - RGB LED Color Cube Documentation
|
Source file with implementation of hardware SPI functions and macros. More...
#include "spi.h"
Functions | |
SPI_Status | spi_init (SPI_Direction direction, SPI_Polarity setup, SPI_Phase sample) |
Initialize the SPI hardware interface in master mode with specified configuration. | |
void | spi_disable (void) |
Disable the SPI hardware interface and reset related pins. | |
void | spi_select (SPI_Select mode) |
Control the SPI Slave Select (SS) pin to enable or disable the SPI slave device. | |
unsigned char | spi_transfer (unsigned char data) |
Transfer a single byte of data over the SPI bus. |
Source file with implementation of hardware SPI functions and macros.
This file contains the definitions of function implementations and macros for hardware-based SPI communication on AVR-0/1/2-Series microcontrollers.
void spi_disable | ( | void | ) |
Disable the SPI hardware interface and reset related pins.
This function disables the SPI peripheral on the AVR ATTiny series device by clearing the master and enable bits in the SPI control register. It also resets the SPI mode bits to their default state. The function configures the SPI-related pins (MOSI, MISO, SCK, SS) by clearing their direction bits, effectively disabling SPI pin control, and drives these pins low by clearing the output register. Additionally, the pull-up resistor on the SS pin is disabled. If SPI interrupts are enabled via the SPI_SPIE macro, this function disables SPI interrupt requests. The port multiplexer configuration for SPI is cleared and the SPI interrupt flags are reset.
SPI_Status spi_init | ( | SPI_Direction | direction, |
SPI_Polarity | setup, | ||
SPI_Phase | sample ) |
Initialize the SPI hardware interface in master mode with specified configuration.
direction | Specifies the bit order for SPI data transmission (MSB or LSB first). |
setup | Specifies the clock polarity (SPI_Polarity) to configure the clock idle state. |
sample | Specifies the clock phase (SPI_Phase) to configure the clock sampling edge. |
This function configures the SPI peripheral registers on the AVR ATTiny series device to initialize the SPI bus in master mode. It sets the SPI port multiplexer, configures the data direction for SPI pins, and sets up the SPI clock phase and polarity according to the specified parameters.
The function also sets pull-up resistors on the MISO and SS pins according to configuration, and configures SPI interrupts if the SPI_SPIE macro is defined.
void spi_select | ( | SPI_Select | mode | ) |
Control the SPI Slave Select (SS) pin to enable or disable the SPI slave device.
mode | Specifies the SPI select state, either SPI_Enable or SPI_Disable. |
This function manages the SPI Slave Select (SS) pin using the configured SPI port. When SPI_Enable is passed, the SS pin is driven low to select (activate) the SPI slave device. For any other value, the SS pin is driven high, deselecting (deactivating) the slave. This control is essential for ensuring that only one SPI slave device communicates with the master at any given time on a shared SPI bus.
unsigned char spi_transfer | ( | unsigned char | data | ) |
Transfer a single byte of data over the SPI bus.
data | The byte value to be sent via SPI. |
This function writes the provided data byte to the SPI data register, initiating the SPI transmission. It then waits in a busy loop until the SPI interrupt flag indicates that the transfer is complete. Upon completion, the function reads and returns the received byte from the SPI data register. SPI communication is full-duplex, so while sending a byte, a byte is received simultaneously. This function therefore effectively performs a combined send/receive operation.