AVRly - AVR Development Resources
|
Driver for SPI communication between the ATmega328P and other SPI compatible devices. More...
Go to the source code of this file.
Functions | |
void | init_spi (spi_transfer_mode_t transfer_mode, spi_control_mode_t control_mode, spi_polarity_mode_t polarity_mode, spi_phase_mode_t phase_mode, spi_clk_rate_t clk_rate, spi_dbl_clk_mode_t dbl_clock) |
Initialisation routine to set up SPI comms. More... | |
uint8_t | spi_trade_byte (uint8_t data) |
Sends out a byte of data over SPI and returns the byte it receives. More... | |
uint16_t | spi_trade_word (uint16_t data) |
Sends out a 16bit word of data over spi (in two bytes) and returns the byte it receives. More... | |
Driver for SPI communication between the ATmega328P and other SPI compatible devices.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file provides the basic SPI comms setup and initialisation instructions. The following ports/pins must be defined in pin_defines.h: SPI_DDR, SPI_PORT, SPI_MOSI SPI_MISO, SPI_SCK, SPI_SS.
Definition in file atmega_spi.c.
void init_spi | ( | spi_transfer_mode_t | transfer_mode, |
spi_control_mode_t | control_mode, | ||
spi_polarity_mode_t | polarity_mode, | ||
spi_phase_mode_t | phase_mode, | ||
spi_clk_rate_t | clk_rate, | ||
spi_dbl_clk_mode_t | dbl_clock | ||
) |
Initialisation routine to set up SPI comms.
Must be called before any other functions in this file can be used.
transfer_mode | lsb_first or msb_first. |
control_mode | controller or peripheral. |
polarity_mode | rising_edge or falling_edge. |
phase_mode | lead_sample_rising_edge or lead_setup_rising_edge. |
clk_rate | Sets the speed of the SPI clock - divided down from F_CPU speed. |
dbl_clock | single_speed or double_speed. |
Definition at line 53 of file atmega_spi.c.
uint8_t spi_trade_byte | ( | uint8_t | data | ) |
Sends out a byte of data over SPI and returns the byte it receives.
uint8_t | data: The byte of data to be sent from the host MCU to the peripheral device. |
Definition at line 85 of file atmega_spi.c.
uint16_t spi_trade_word | ( | uint16_t | data | ) |
Sends out a 16bit word of data over spi (in two bytes) and returns the byte it receives.
uint16_t | data: The byte of data to be sent from the host MCU to the peripheral device. |
Definition at line 98 of file atmega_spi.c.