-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPI.c
More file actions
57 lines (41 loc) · 871 Bytes
/
Copy pathSPI.c
File metadata and controls
57 lines (41 loc) · 871 Bytes
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
/*
* SPI.c
*
* Created: 5/14/2018 10:42:48 AM
* Author: Ahmed Hussein
*/
#include "SPI.h"
void vSPI_SlaveInit(void)
{
DIR_SPI = (1<<DD_MISO);
SPCR = (1<<SPE)|(1<<DORD)|(1<<SPIE); /* DORD -> I need to send the LSB first cuz the password is consisted of ones cuz when I send the MSB first the logic was incorrect*/
return;
}
char cSPI_SlaveReceive(void)
{
while(!(SPSR & (1<<SPIF)));
return SPDR;
}
void vSPI_SlaveTransmit(char Data)
{
SPDR = Data;
while(!(SPSR & (1<<SPIF)));
return;
}
char cSPI_MasterReceive(void)
{
while(!(SPSR & (1<<SPIF)));
return SPDR;
}
void vSPI_MasterTransmit(char Data)
{
SPDR = Data;
while(!(SPSR & (1<<SPIF)));
return;
}
void vSPI_MasterInit(void)
{
DIR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
return;
}