xyControl  0.1
Quadrotor Flight Controller on AVR Basis
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Files | Enumerations | Functions
SPI Driver

SPI Library for AVRs built-in SPI Hardware. More...

Files

file  spi.h
 SPI API Header.
 
file  spi.c
 SPI API Implementation.
 

Enumerations

enum  SPI_MODE { MODE_0 = 0, MODE_1 = 1, MODE_2 = 2, MODE_3 = 3 }
 SPI Mode option. More...
 
enum  SPI_SPEED {
  SPEED_2 = 4, SPEED_4 = 0, SPEED_8 = 5, SPEED_16 = 1,
  SPEED_32 = 6, SPEED_64 = 2, SPEED_128 = 3
}
 SPI Speed options. More...
 

Functions

void spiInit (SPI_MODE mode, SPI_SPEED speed)
 Initialize the SPI Hardware Module. More...
 
uint8_t spiSendByte (uint8_t d)
 Send and Receive one byte. More...
 

Detailed Description

SPI Library for AVRs built-in SPI Hardware.

Enumeration Type Documentation

enum SPI_MODE

SPI Mode option.

Enumerator
MODE_0 

CPOL 0, CPHA 0.

MODE_1 

CPOL 0, CPHA 1.

MODE_2 

CPOL 1, CPHA 0.

MODE_3 

CPOL 1, CPHA 1.

Definition at line 44 of file spi.h.

44  {
45  MODE_0 = 0,
46  MODE_1 = 1,
47  MODE_2 = 2,
48  MODE_3 = 3,
49 } SPI_MODE;
enum SPI_SPEED

SPI Speed options.

Enumerator
SPEED_2 

F_CPU / 2.

SPEED_4 

F_CPU / 4.

SPEED_8 

F_CPU / 8.

SPEED_16 

F_CPU / 16.

SPEED_32 

F_CPU / 32.

SPEED_64 

F_CPU / 64.

SPEED_128 

F_CPU / 128.

Definition at line 52 of file spi.h.

52  {
53  SPEED_2 = 4,
54  SPEED_4 = 0,
55  SPEED_8 = 5,
56  SPEED_16 = 1,
57  SPEED_32 = 6,
58  SPEED_64 = 2,
59  SPEED_128 = 3,
60 } SPI_SPEED;

Function Documentation

void spiInit ( SPI_MODE  mode,
SPI_SPEED  speed 
)

Initialize the SPI Hardware Module.

Parameters
modeSPI Mode to use
speedSPI Speed to use

Referenced by xyInit().

uint8_t spiSendByte ( uint8_t  d)

Send and Receive one byte.

Set the Chip Select Lines yourself!

Parameters
dData to be sent
Returns
Byte read from Bus

Definition at line 54 of file spi.c.

54  {
55  SPDR = d;
56  while (!(SPSR & (1 << SPIF))); // Wait for transmission
57  return SPDR;
58 }