-
Notifications
You must be signed in to change notification settings - Fork 14
/
spi.h
48 lines (42 loc) · 1.59 KB
/
spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef __SPI_H__
#define __SPI_H__
/*******************************************************************************
* spi.h v1 - 11/02/2018
Initial definitions
* spi.h v2 - 11/07/2018
Updated initialization function
*******************************************************************************/
#ifdef __AVR__
// pin definitions
#define DDR_SPI DDRB
#define PORT_SPI PORTB
#define CS PINB2
#define MOSI PINB3
#define MISO PINB4
#define SCK PINB5
// macros
#define CS_ENABLE() PORT_SPI &= ~(1 << CS)
#define CS_DISABLE() PORT_SPI |= (1 << CS)
#endif
// initialization definitions
#define SPI_MASTER 0b0001000000000000
#define SPI_SLAVE 0b0000000000000000
#define SPI_FOSC_4 0b0000000000000000
#define SPI_FOSC_8 0b0000010100000000
#define SPI_FOSC_16 0b0000000100000000
#define SPI_FOSC_64 0b0000001000000000
#define SPI_FOSC_128 0b0000001100000000
#define SPI_2X_FOSC_2 0b0000000000000001
#define SPI_2X_FOSC_8 0b0000000100000001
#define SPI_2X_FOSC_32 0b0000001000000001
#define SPI_2X_FOSC_64 0b0000001100000001
#define SPI_INTERRUPTS 0b1000000000000000
#define SPI_MODE_0 0b0000000000000000
#define SPI_MODE_1 0b0000010000000000
#define SPI_MODE_2 0b0000100000000000
#define SPI_MODE_3 0b0000110000000000
#define SPI_DEFAULT SPI_MASTER | SPI_FOSC_128 | SPI_MODE_0
// SPI functions
void SPI_init(uint16_t initParams);
uint8_t SPI_transfer(uint8_t data);
#endif