-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPongInt
95 lines (71 loc) · 2.56 KB
/
PongInt
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
95
\ Reveiver (Pong) for STM8 eForth nRF24L01 with interrupt handler
\ load STM8S103 register addresse as constants
\res MCU: STM8S103
\res export BIT0 BIT1 BIT2 BIT3 BIT4 BIT5 BIT6 BIT7
\res export INT_EXTI2
\res MCU: nRF24L01
\res export R.SETUP_RETR R.STATUS R.OBSERVE_TX R.DYNPD R.FEATURE
\ helper word: create BSET/BRES instructions
#require ]B!
NVM
: FlashLed ( -- ) LED.ON 2 ms LED.Off ;
: TX.PWR0 ( -- ) \ Set to 250kbps and 0dBm (SI24R1: +7dBm) output
[ $0 BIT5 >HIGH BIT2 >HIGH BIT1 >HIGH BIT0 >HIGH ] LITERAL RfSetup
;
: InitAckPayload ( -- ) \ PRX and PTX config for payload in ACK
( DPL_P0 ) $01 R.DYNPD nRF!1
( EN_ACK_PAY ) $02 R.FEATURE nRF!1 \ see footnote ^d
;
: SetAckPayload ( -- ) \ copy ACK payload to nRF24
RXBUFF 20 + 4 0 ( b c p ) b>ack DROP \ payload (transmit counter)
;
VARIABLE STATUS \ nRF24 STATUS from IRQ
\ interrupt service routine
HERE ] \ headerless code (keep xt on stack)
SAVEC
LED.On \ signal: interrupt has been serviced
RXBUFF P0_WIDTH rx>b STATUS !
$70 R.STATUS nRF!1
IRET
[ OVERT ( xt ) INT_EXTI2 ! \ set Port C int vector
HERE $05A3 , $B4C5 , $D6E7 , ( myP0Addr )
: RxInit ( -- ) \ setup as primary receiver
nRF24Init \ general setup
0 STATUS !
IrqInit \ enable nRF24 IRQ interrupt
\ set pipe0 RX/TX to same address
( myP0Addr ) LITERAL COUNT b>p0addr
\ configure ACK payload mode
( DPL_P0 ) $01 R.DYNPD nRF!1
( EN_ACK_PAY ) $02 R.FEATURE nRF!1 \ see footnote ^d
P0_WIDTH SetPL_width \ effectively enables Pipe0
\ set TX power to 0dBm output, modulation to 250kbps
[ $0 BIT5 >HIGH BIT2 >HIGH BIT1 >HIGH ] LITERAL RfSetup
\ ARD: retransmit delay, ARC: retries
( ARD: 8*250us, ARC: 15* ) $8F R.SETUP_RETR nRF!1
$70 SetRF_CH
>Standby1
InitAckPayload
Set.RX
." Device reset" cr
;
: Pong ( -- ) \ Pong until space char on serial console
RxInit \ now acting as a RX in standby state
FlashLed \ on power up flash led so we know device is a pong
500 ms FlashLed
SetAckPayload \ dummy data for the first received packet
_CE.HD \ Enter RX state
BEGIN
STATUS @ IF
\ print buffer and nRF STATUS from receive int
RXBUFF P0_WIDTH TYPE STATUS ? CR
0 STATUS !
LED.Off \ signal: message has been consumed
SetAckPayload \ in a real application this would be time-synced
THEN
?RX \ input on serial line
IF 32 = ELSE 0 THEN \ only if it is a space char do we exit
UNTIL
;
' Pong 'Boot ! \ install start-up routine
RAM