-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSPI_SETUP.F
94 lines (77 loc) · 1.84 KB
/
SPI_SETUP.F
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
85
86
87
88
89
90
91
92
93
94
\ SPI SETUPS
\ ADDAPTED FROM JEELABS/EMBELLO
\ REFER TO STM PDF RM0008 FOR GPIO SETUPS
HEX
: BIT ( PIN# - BIT ) \ USED AS A GENERAL PORT MASK VALUE
1 SWAP LSHIFT ;
: CONF ( PIN# - MASK OFFSET ) \ USED FOR MODE AND CONFIG
4 * 20 /MOD
4 *
0F ROT LSHIFT
SWAP ;
\ MODE MASK FIRST THEN MODIFIERS
CCCCCCCC CONSTANT INMODE
33333333 CONSTANT OUT50
11111111 CONSTANT OUT10
22222222 CONSTANT OUT2
\ CONFIG MODIFIERS
\ INPUT MODIFIERS
: ANALOG 0 AND ;
: FLOAT 44444444 AND ;
: UP/DN 88888888 AND ;
\ OUTS TYPE MODIFIERS
: ALT 88888888 OR ;
: P/P ;
: DRAIN 44444444 OR ;
\ GPIO DATA PORTS OFFSETS
08 CONSTANT INPUT
10 CONSTANT S/R
0C CONSTANT OUTPUT
\ ON Port A
4 CONSTANT SSEL#
5 CONSTANT SCLK#
6 CONSTANT MISO#
7 CONSTANT MOSI#
SSEL# BIT CONSTANT SSEL
SCLK# BIT CONSTANT SCLK
MISO# BIT CONSTANT MISO
MOSI# BIT CONSTANT MOSI
40013000 CONSTANT SPI1
SPI1 0 + CONSTANT SPI1-CR1
SPI1 4 + CONSTANT SPI1-CR2
SPI1 8 + CONSTANT SPI1-SR
SPI1 C + CONSTANT SPI1-DR
: +SPI ( - ) SSEL 0 PA+ CLR! ;
: -SPI ( - ) SSEL 0 PA+ SET! ;
: SPI-INIT ( - )
OUT10 P/P SSEL# CONF PA+ MSK!
OUT10 P/P ALT SCLK# CONF PA+ MSK!
INMODE FLOAT MISO# CONF PA+ MSK!
OUT10 P/P ALT MOSI# CONF PA+ MSK!
1000 DUP 40021018 ( RCC_APB2ENR ) MSK! \ ENABLE CLOCK
4 ( SSOE ) DUP SPI1-CR2 MSK!
SPI1-SR @ DROP \ STOPS HANGES
50 SPI1-CR1 !
SPI1-SR @ DROP
54 SPI1-CR1 ! ;
: SPI-CLK ( - )
SPI1-SR @ 1 AND
IF SPI1-DR @ DROP THEN
BEGIN
SPI1-SR @ 2 AND
UNTIL
0FF SPI1-DR ! ;
: >SPI> ( C - C )
BEGIN
SPI1-SR @ 2 AND
UNTIL
SPI1-DR !
BEGIN
SPI1-SR @ 1 AND \ WAIT RESPONSE
UNTIL SPI1-DR @ ;
: SPI> ( - C ) 0 >SPI> ;
: >SPI ( C - ) >SPI> DROP ;
: SPI. ( - ) \ DISPLAY REGS
CR ." CR1 " SPI1-CR1 @ .
." CR2 " SPI1-CR2 @ .
." SR " SPI1-SR @ . ;