-
Notifications
You must be signed in to change notification settings - Fork 0
/
main spi with loop back.c
84 lines (61 loc) · 1.91 KB
/
main spi with loop back.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//SPI with LOOP Back
#include <stdint.h>
#define RCGCGPIO (*((volatile unsigned long *)0x400FE608))
#define GPIOAFSEL (*((volatile unsigned long *)0x40004420))
#define GPIODEN (*((volatile unsigned long *)0x4000451c))
#define GPIOPCTL (*((volatile unsigned long *)0x4000452c))
#define RCGCSSI (*((volatile unsigned long *)0x400fe61c))
#define SSICR1 (*((volatile unsigned long *)0x40008004))
#define SSICPSR (*((volatile unsigned long *)0x40008010))
#define SSICR0 (*((volatile unsigned long *)0x40008000))
#define SSISR (*((volatile unsigned long *)0x4000800c))
#define SSIDR (*((volatile unsigned long *)0x40008008))
#define GPIODIR (*((volatile unsigned long *)0x40004400))
#define GPIODATA (*((volatile unsigned long *)0x40004000))
#define SSICC (*((volatile unsigned long *)0x40008FC8))
#define GPIOPDR (*((volatile unsigned long *)0x40004514))
void SPI_init(void)
{
RCGCSSI |= 0x1; // enable spi clock
RCGCGPIO |= 0x1; // enable gpio clock
GPIOAFSEL |= 0x3c; // PA[5:2] alternate
GPIOPCTL |= 0x222200; // pctl
GPIODEN |= 0x3c;
GPIOPDR |= 0x08;
//pull up is missed
// ssi config
SSICR1 &= ~0x02; //disable sse bit
SSICR1 |= 0x00; // master
SSICC |=0x0; //clock mode
SSICR0 |= 0x07; //8-bit data frame
SSICR1 |= 0x03; // enable and LBM
}
uint8_t tx (uint8_t data);
uint8_t rx ();
int main(void) {
uint8_t DR=0 ;
uint8_t REC=0 ;
SPI_init();
while (1){
DR= tx(0xAA);
REC= rx();
}
return 0;
}
uint8_t tx (uint8_t data)
{ SSIDR = data;
while((SSISR & 2)==0); //wait until TNF bit is equal 1
return SSIDR;
}
uint8_t rx ()
{ uint8_t data =0;
while((SSISR & 4)== 1); //wait until RNE bit is equal 0
data= SSIDR+1;
return data;
}
/*uint8_t SPI_TRSF (uint8_t data)
{
SSIDR = data;
while (!(SSISR & 0x04));
return SSIDR;
}*/