Embedded C Firmware Library : Arduino / Atmega328p
1
Register Level Embedded C Hardware Abstraction Library for AVR ATmega48A/PA/88A/PA/168A/PA/328/P or Arduino UNO/NANO/MINI
|
Library for SPI Communication. More...
Go to the source code of this file.
Data Structures | |
struct | SPI_ConfigData |
Macros | |
SPI_MODE_MASTER_SLAVE | |
Options for SPI Hardware Operation Mode | |
#define | SPI_MODE_MASTER (1<<MSTR) |
#define | SPI_MODE_SLAVE (0<<MSTR) |
#define | SPI_MODE_MASK (1<<MSTR) |
SPI_ENABLE_DISABLE | |
Options for SPI Hardware Operation Mode | |
#define | SPI_ENABLE (1<<SPE) |
SPI_PRESCALER | |
Options for SPI SCK Clock Prescaler | |
#define | SPI_PRESCALER_4 (0<<SPR1) | (0<<SPR0) |
#define | SPI_PRESCALER_16 (1<<SPR0) |
#define | SPI_PRESCALER_64 (1<<SPR1) |
#define | SPI_PRESCALER_128 (1<<SPR1) | (1<<SPR0) |
#define | SPI_PRESCALER_MASK (1<<SPR1) | (1<<SPR0) |
#define | SPI_PRESCALER_SPEED_DOUBLE (1<<SPI2X) |
#define | SPI_PRESCALER_SPEED_NORMAL (0<<SPI2X) |
#define | SPI_PRESCALER_SPEED_MASK (1<<SPI2X) |
SPI_DATA_MODE | |
Options for SPI SCK Clock Phase and Polarity | |
#define | SPI_DATA_MODE_0 (0<<CPOL) | (0<<CPHA) |
#define | SPI_DATA_MODE_1 (1<<CPHA) |
#define | SPI_DATA_MODE_2 (1<<CPOL) |
#define | SPI_DATA_MODE_3 (1<<CPOL) | (1<<CPHA) |
#define | SPI_DATA_MODE_MASK (1<<CPOL) | (1<<CPHA) |
SPI_DATA_ORDER | |
Options for SPI Serial Data Transmission Order | |
#define | SPI_DATA_ORDER_LSB_FIRST (1<<DORD) |
#define | SPI_DATA_ORDER_MSB_FIRST (0<<DORD) |
#define | SPI_DATA_ORDER_MASK (1<<DORD) |
SPI_PINS | |
GPIO Pins for SPI Communication | |
#define | SPI_MISO_PIN (1<<4) |
#define | SPI_MOSI_PIN (1<<3) |
#define | SPI_SCK_PIN (1<<5) |
#define | SPI_SS_PIN (1<<2) |
#define | SPI_PORT PORTB |
#define | SPI_DDR DDRB |
Typedefs | |
SPI_CONFIGURATION_DATA | |
Structure used to Configure SPI | |
typedef struct SPI_ConfigData | SPI_ConfigData |
Functions | |
SPI_CONFIGURATION_AND_CONTROL | |
Public Functions to Control and Configure SPI | |
void | SPI_Init (SPI_ConfigData Data) |
Public Function to Configure and Initialize SPI. More... | |
void | SPI_DeInit () |
Public Function to De-Initialize SPI. More... | |
SPI_RECEIVE | |
Public Functions to Simplex / Half-Duplex Receive Data via SPI | |
uint8_t | SPI_ReceiveByte () |
Public Function to Receive 1 Byte of Data in Polling. More... | |
uint16_t | SPI_ReceiveTwoBytes () |
Public Function to Receive 2 Bytes / 16 Bits of Data in Polling. More... | |
void | SPI_ReceiveBytes (uint8_t *Buffer, uint8_t Size) |
Public Function to Receive Multiple Bytes of Data in Polling. More... | |
SPI_TRANSMIT | |
Public Functions to Simplex / Half-Duplex Transmit Data via SPI | |
void | SPI_TransmitByte (uint8_t Buffer) |
Public Function to Transmit 1 Byte of Data in Polling. More... | |
void | SPI_TransmitTwoBytes (uint16_t Buffer) |
Public Function to Transmit 2 Bytes / 16 Bits of Data in Polling. More... | |
void | SPI_TransmitBytes (uint8_t *Buffer, uint8_t Size) |
Public Function to Transmit Multiple Bytes of Data in Polling. More... | |
SPI_TRANSRECEIVE | |
Public Functions to Duplex Transmit and Receive Data via SPI | |
uint8_t | SPI_TransReceiveByte (uint8_t Buffer) |
Public Function to TransReceive 1 Byte of Data in Polling. More... | |
uint16_t | SPI_TransReceiveTwoBytes (uint16_t Buffer) |
Public Function to TransReceive 2 Byte / 16 Bits of Data in Polling. More... | |
void | SPI_TransReceiveBytes (uint8_t *Buffer, uint8_t Size) |
Public Function to TransReceive Multiple Bytes of Data in Polling. More... | |
Library for SPI Communication.
Created: 01-05-2020 08:20:10 PM Author : Arnab Kumar Das Website: www.ArnabKumarDas.com Microcontroller Supported: ATmega48A/PA/88A/PA/168A/PA/328/P or Arduino UNO/NANO/MINI +-\/-+ PC6 1| |28 PC5 (A5/ADC5) RXD (D0) PD0 2| |27 PC4 (A4/ADC4) TXD (D1) PD1 3| |26 PC3 (A3/ADC3) (D2) PD2 4| |25 PC2 (A2/ADC2) PWM (D3) PD3 5| |24 PC1 (A1/ADC1) XCK (D4) PD4 6| |23 PC0 (A0/ADC0) VCC 7| |22 GND GND 8| |21 AREF PB6 9| |20 AVCC PB7 10| |19 PB5 (D13) SCK OC0B (D5) PD5 11| |18 PB4 (D12) MISO OC0A (D6) PD6 12| |17 PB3 (D11) MOSI (D7) PD7 13| |16 PB2 (D10) SS (D8) PB0 14| |15 PB1 (D9) PWM +----+
#define SPI_MODE_MASTER (1<<MSTR) |
Sets the SPI Hardware Operation Mode to : Master Mode
#define SPI_MODE_SLAVE (0<<MSTR) |
Sets the SPI Hardware Operation Mode to : Slave Mode
#define SPI_MODE_MASK (1<<MSTR) |
Mask for SPI Hardware Operation Mode
#define SPI_ENABLE (1<<SPE) |
Enables the SPI Hardware
#define SPI_PRESCALER_4 (0<<SPR1) | (0<<SPR0) |
Sets the SPI Clock Source to : F_CPU/4 : System Clock Divided by 4
#define SPI_PRESCALER_16 (1<<SPR0) |
Sets the SPI Clock Source to : F_CPU/16 : System Clock Divided by 16
#define SPI_PRESCALER_64 (1<<SPR1) |
Sets the SPI Clock Source to : F_CPU/64 : System Clock Divided by 64
#define SPI_PRESCALER_128 (1<<SPR1) | (1<<SPR0) |
Sets the SPI Clock Source to : F_CPU/128 : System Clock Divided by 128
#define SPI_PRESCALER_MASK (1<<SPR1) | (1<<SPR0) |
Mask for SPI Prescaler
#define SPI_PRESCALER_SPEED_DOUBLE (1<<SPI2X) |
Sets the SPI Clock Source to : (F_CPU/PRESCALER)/2 : System Clock Divided by 2*PRESCALER
#define SPI_PRESCALER_SPEED_NORMAL (0<<SPI2X) |
Sets the SPI Clock Source to : (F_CPU/PRESCALER)/1 : System Clock Divided by 1*PRESCALER
#define SPI_PRESCALER_SPEED_MASK (1<<SPI2X) |
Mask for SPI Double Speed Prescaler
#define SPI_DATA_MODE_0 (0<<CPOL) | (0<<CPHA) |
Sets the SCK Phase and Polarity WRT Serial Data : Leading Edge Sample (Rising) Trailing Edge Setup (Falling)
#define SPI_DATA_MODE_1 (1<<CPHA) |
Sets the SCK Phase and Polarity WRT Serial Data : Leading Edge Setup (Rising) Trailing Edge Sample (Falling)
#define SPI_DATA_MODE_2 (1<<CPOL) |
Sets the SCK Phase and Polarity WRT Serial Data : Leading Edge Sample (Falling) Trailing Edge Setup (Rising)
#define SPI_DATA_MODE_3 (1<<CPOL) | (1<<CPHA) |
Sets the SCK Phase and Polarity WRT Serial Data : Leading Edge Setup (Falling) Trailing Edge Sample (Rising)
#define SPI_DATA_MODE_MASK (1<<CPOL) | (1<<CPHA) |
Mask for SPI SCK Phase and Polarity
#define SPI_DATA_ORDER_LSB_FIRST (1<<DORD) |
Sets the SPI Serial Data Transmission Order : LSB First
#define SPI_DATA_ORDER_MSB_FIRST (0<<DORD) |
Sets the SPI Serial Data Transmission Order : MSB First
#define SPI_DATA_ORDER_MASK (1<<DORD) |
Mask for SPI Serial Data Transmission Order
void SPI_Init | ( | SPI_ConfigData | Data | ) |
Public Function to Configure and Initialize SPI.
[in] | Data | : Structure Variable containing SPI Configuration Data |
SPI_ConfigData Data1; Data1.DataMode = SPI_DATA_MODE_0; Data1.DataOrder = SPI_DATA_ORDER_MSB_FIRST; Data1.DoubleSpeed = SPI_PRESCALER_SPEED_NORMAL; Data1.Prescaler = SPI_PRESCALER_128; Data1.MasterSlaveSelect = SPI_MODE_MASTER; SPI_Init(Data1);
void SPI_DeInit | ( | ) |
Public Function to De-Initialize SPI.
uint8_t SPI_ReceiveByte | ( | ) |
Public Function to Receive 1 Byte of Data in Polling.
uint16_t SPI_ReceiveTwoBytes | ( | ) |
Public Function to Receive 2 Bytes / 16 Bits of Data in Polling.
void SPI_ReceiveBytes | ( | uint8_t * | Buffer, |
uint8_t | Size | ||
) |
Public Function to Receive Multiple Bytes of Data in Polling.
[out] | Buffer | : Pointer to Memory Location to Store Data |
[in] | Size | : Variable to Store Number of Bytes to TransReceive |
void SPI_TransmitByte | ( | uint8_t | Buffer | ) |
Public Function to Transmit 1 Byte of Data in Polling.
void SPI_TransmitTwoBytes | ( | uint16_t | Buffer | ) |
Public Function to Transmit 2 Bytes / 16 Bits of Data in Polling.
void SPI_TransmitBytes | ( | uint8_t * | Buffer, |
uint8_t | Size | ||
) |
Public Function to Transmit Multiple Bytes of Data in Polling.
[out] | Buffer | : Pointer to Memory Location to Store Data |
[in] | Size | : Variable to Store Number of Bytes to Transmit |
uint8_t SPI_TransReceiveByte | ( | uint8_t | Buffer | ) |
Public Function to TransReceive 1 Byte of Data in Polling.
uint16_t SPI_TransReceiveTwoBytes | ( | uint16_t | Buffer | ) |
Public Function to TransReceive 2 Byte / 16 Bits of Data in Polling.
void SPI_TransReceiveBytes | ( | uint8_t * | Buffer, |
uint8_t | Size | ||
) |
Public Function to TransReceive Multiple Bytes of Data in Polling.
[out] | Buffer | : Pointer to Memory Location to Store Data |
[in] | Size | : Variable to Store Number of Bytes to TransReceive |