-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspi_2.h
64 lines (41 loc) · 1.58 KB
/
spi_2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef SPI_H
#define SPI_H
#include <avr/io.h>
#define SPI_PORTX PORTB
#define SPI_DDRX DDRB
#define SPI_MISO 6
#define SPI_MOSI 5
#define SPI_SCK 7
#define SPI_SS 4
/*_______________ ìàêðîñû ____________________*/
/*çàïðåòèòü SPI óñòðîéñòâî*/
#define SPI_DisableSS_m(ss) do{SPI_PORTX |= (1<<(ss)); }while(0)
/*ðàçðåøèòü SPI óñòðîéñòâî*/
#define SPI_EnableSS_m(ss) do{SPI_PORTX &= ~(1<<(ss)); }while(0)
/*ñòàòóñ SPI óñòðîéñòâà*/
#define SPI_StatSS_m(ss) (!(SPI_PORTX & (1<<(ss))))
/*ïåðåäàòü áàéò äàííûõ ïî SPI*/
#define SPI_WriteByte_m(data) do{ SPDR = data; while(!(SPSR & (1<<SPIF))); }while(0)
/*ïðî÷èòàòü áàéò äàííûõ ïî SPI*/
#define SPI_ReadByte_m(data) do{ SPDR = 0xff; while(!(SPSR & (1<<SPIF))); data = SPDR;}while(0)
/* ______________ âñòðàèâàåìûå ôóíêöèè _____________*/
/*ïîëó÷èòü áàéò äàííûõ ïî SPI*/
inline static unsigned char SPI_ReadByte_i(void){
SPDR = 0xff;
while(!(SPSR & (1<<SPIF)));
return SPDR;
}
/* _________________ ôóíêöèè ________________ */
/*èíèöèàëèçàöèÿ SPI ìîäóëÿ*/
void SPI_Init(void);
/*îòïðàâèòü áàéò äàííûõ ïî SPI*/
void SPI_WriteByte(unsigned char data);
/*ïîëó÷èòü áàéò äàííûõ ïî SPI*/
unsigned char SPI_ReadByte(void);
/*îòïðàâèòü è ïîëó÷èòü áàéò äàííûõ ïî SPI*/
unsigned char SPI_WriteReadByte(unsigned char data);
/*îòïðàâèòü íåñêîëüêî áàéò äàííûõ ïî SPI*/
void SPI_WriteArray(unsigned char num, unsigned char *data);
/*îòïðàâèòü è ïîëó÷èòü íåñêîëüêî áàéò äàííûõ ïî SPI*/
void SPI_WriteReadArray(unsigned char num, unsigned char *data);
#endif //SPI_H