-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSPI_prog.c
More file actions
63 lines (47 loc) · 853 Bytes
/
Copy pathSPI_prog.c
File metadata and controls
63 lines (47 loc) · 853 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
58
59
60
61
/*
* SPI_prog.c
*
* Created on: Nov 30, 2018
* Author: abood
*/
#include "LIB/STD_TYPES.h"
#include "LIB/BIT_MATH.h"
#include "SPI_reg.h"
#include "SPI_int.h"
#include "SPI_priv.h"
#include "SPI_cfg.h"
void SPI_VidInit(void)
{
/* set clock prescaler */
CLR_BIT(SPCR,SPR0);
CLR_BIT(SPCR,SPR1);
SET_BIT(SPSR,SPI2X);
//SPSR=(1<<SPI2X);
/* SET MODE 1 */
CLR_BIT(SPCR,CPOL);
CLR_BIT(SPCR,CPHA);
/* SET COMM_MODE */
if(COMM_MODE == MASTER_MODE)
{
SET_BIT(SPCR,MSTR);
}
else if(COMM_MODE == SLAVE_MODE)
{
CLR_BIT(SPCR,MSTR);
}
else
{
/* do nothing */
}
/* ENABLE SPI */
SET_BIT(SPCR,SPE);
}
u8 SPI_u8SendReceiveData(u8 u8DataSend)
{
/* SET DATA TO SEND */
SPDR = u8DataSend ;
/* wait till transmission complete (SPIF flag set) */
while(GET_BIT(SPSR,SPIF) == 0);
/* return read data */
return SPDR;
}