HP85 GPIB Disk Emulator  1.0
HP85GPIBDiskEmulator
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions | Variables
spi.c File Reference

SPI Driver AVR8. More...

#include "user_config.h"
#include <stdlib.h>
#include "spi.h"

Go to the source code of this file.

Functions

void SPI0_Speed (uint32_t speed)
 Set AVR SPI bus rate in HZ. More...
 
uint32_t SPI0_Get_Speed (void)
 Return previously saved SPI BUS rate in HZ. More...
 
void SPI0_Mode (int mode)
 Set SPI clock mode. More...
 
int SPI0_Get_Mode (void)
 Return saved SPI mode as set by SPI0_Mode(). More...
 
void SPI0_Init (uint32_t speed)
 Initialize SPI0 device. See Atmel App Note AVR151 Set default speed, IO pins and mode. More...
 
uint8_t SPI0_TXRX_Byte (uint8_t Data)
 SPI read/Write byte. More...
 
void SPI0_TX (uint8_t *data, int count)
 SPI buffered write functions. More...
 
void SPI0_TXRX (uint8_t *data, int count)
 HSPI write and read using FIFO. More...
 
void SPI0_RX (uint8_t *data, int count)
 HSPI read using FIFO. More...
 

Variables

static uint32_t SPI0_Speed_value = 0
 Saved SPI bus speed. More...
 
static int SPI0_Mode_value = 0
 Saved SPI Mode. More...
 
static int SPI0_Init_state = 0
 SPI0 initialization flag. More...
 

Detailed Description

SPI Driver AVR8.

Edit History
  • [1.0] [Mike Gore] Initial revision of file.
Author
Mike Gore

Definition in file spi.c.

Function Documentation

◆ SPI0_Get_Mode()

int SPI0_Get_Mode ( void  )

Return saved SPI mode as set by SPI0_Mode().

Returns
saved mode.

Definition at line 180 of file spi.c.

◆ SPI0_Get_Speed()

uint32_t SPI0_Get_Speed ( void  )

Return previously saved SPI BUS rate in HZ.

Returns
SPI clock rate in HZ.

Definition at line 128 of file spi.c.

◆ SPI0_Init()

void SPI0_Init ( uint32_t  speed)

Initialize SPI0 device. See Atmel App Note AVR151 Set default speed, IO pins and mode.

Set SPI clock mode 0 SPI Mode CPOL CPHA Sample 0 0 0 Leading (Rising) Edge

Definition at line 192 of file spi.c.

Referenced by spi_init().

◆ SPI0_Mode()

void SPI0_Mode ( int  mode)

Set SPI clock mode.

Parameters
[in]modevalid mades:
*   SPI Mode     CPOL    CPHA            Sample
*   0    0       0       Leading (Rising)   Edge
*   1    0       1       Trailing (Falling) Edge
*   2    1       0       Leading (Falling)  Edge
*   3    1       1       Trailing (Rising)  Edge
* 
Returns
void

Definition at line 150 of file spi.c.

Referenced by SPI0_Init(), and spi_init().

◆ SPI0_RX()

void SPI0_RX ( uint8_t *  data,
int  count 
)

HSPI read using FIFO.

Parameters
[in]*datareceive buffer
[in]countnumber of bytes to read
Returns
void

Definition at line 297 of file spi.c.

Referenced by spi_RX(), and spi_RX_buffer().

◆ SPI0_Speed()

void SPI0_Speed ( uint32_t  speed)

Set AVR SPI bus rate in HZ.

  • Compute precsale rate from desired frequency in HZ.
    • Slowest rate: F_CPU/128.
    • Fastest rate: F_CPU/2.
  • Precsale value is truncated not rounded.
  • Valid precsle values are 2,4,8,16,32,64,128.
    /// SPI2X   SPR1    SPR0     SCK Frequency
    /// 1       0       0        fosc/2
    /// 0       0       0        fosc/4
    /// 1       0       1        fosc/8
    /// 0       0       1        fosc/16
    /// 1       1       0        fosc/32
    /// 0       1       0        fosc/64
    /// 1       1       1        fosc/64
    /// 0       1       1        fosc/128
    /// 
    @param[in] speed: SPI clock rate in HZ.
    
    @return  void 
    

Save speed value

Definition at line 46 of file spi.c.

Referenced by SPI0_Init().

◆ SPI0_TX()

void SPI0_TX ( uint8_t *  data,
int  count 
)

SPI buffered write functions.

HSPI write using FIFO

Parameters
[in]*datatransmit buffer
[in]countnumber of bytes to write
Returns
void

Definition at line 264 of file spi.c.

Referenced by spi_TX(), and spi_TX_buffer().

◆ SPI0_TXRX()

void SPI0_TXRX ( uint8_t *  data,
int  count 
)

HSPI write and read using FIFO.

Parameters
[in]*datatransmit / receive buffer
[in]countnumber of bytes to write / read
Returns
void

Definition at line 281 of file spi.c.

Referenced by spi_TXRX(), and spi_TXRX_buffer().

◆ SPI0_TXRX_Byte()

uint8_t SPI0_TXRX_Byte ( uint8_t  Data)

SPI read/Write byte.

  • We Write and read at the same time.
  • If we want to read only set Data to 0xff.
Parameters
[in]DataData to send.
Returns
Data received.

Definition at line 245 of file spi.c.

Referenced by ppr_set(), SPI0_Init(), SPI0_RX(), SPI0_TX(), and SPI0_TXRX().

Variable Documentation

◆ SPI0_Init_state

int SPI0_Init_state = 0
static

SPI0 initialization flag.

Definition at line 187 of file spi.c.

Referenced by SPI0_Init().

◆ SPI0_Mode_value

int SPI0_Mode_value = 0
static

Saved SPI Mode.

See also
SPI0_Mode().

Definition at line 136 of file spi.c.

Referenced by SPI0_Get_Mode(), and SPI0_Mode().

◆ SPI0_Speed_value

uint32_t SPI0_Speed_value = 0
static

Saved SPI bus speed.

Definition at line 22 of file spi.c.

Referenced by SPI0_Get_Speed(), and SPI0_Speed().