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

SPI Driver AVR8. More...

#include "user_config.h"

Go to the source code of this file.

Macros

#define SPI0_MODE0   0
 
#define SPI0_MODE1   1
 
#define SPI0_MODE2   2
 
#define SPI0_MODE3   3
 

Functions

void SPI0_cs_enable (uint8_t cs)
 
void SPI0_cs_disable (uint8_t cs)
 
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...
 

Detailed Description

SPI Driver AVR8.

Edit History
  • [1.0] [Mike Gore] Initial revision of file.
Copyright © 2014-2020 Mike Gore, Inc. All rights reserved.

Definition in file spi.h.

Macro Definition Documentation

◆ SPI0_MODE0

#define SPI0_MODE0   0

Definition at line 18 of file spi.h.

◆ SPI0_MODE1

#define SPI0_MODE1   1

Definition at line 19 of file spi.h.

◆ SPI0_MODE2

#define SPI0_MODE2   2

Definition at line 20 of file spi.h.

◆ SPI0_MODE3

#define SPI0_MODE3   3

Definition at line 21 of file spi.h.

Function Documentation

◆ SPI0_cs_disable()

void SPI0_cs_disable ( uint8_t  cs)

◆ SPI0_cs_enable()

void SPI0_cs_enable ( uint8_t  cs)

◆ 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().