-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNRF24L01-SpeedTest-RX.spin
147 lines (111 loc) · 5.25 KB
/
NRF24L01-SpeedTest-RX.spin
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
----------------------------------------------------------------------------------------------------
Filename: NRF24L01-SpeedTest-RX.spin
Description: Speed test for nRF24L01+ modules
* RX Mode
Author: Jesse Burt
Started: Apr 30, 2020
Updated: Aug 26, 2024
Copyright (c) 2024 - See end of file for terms of use.
----------------------------------------------------------------------------------------------------
}
CON
_clkmode = xtal1+pll16x
_xinfreq = 5_000_000
' -- User-modifiable constants
PKTLEN = 32 ' 1..32 (bytes)
CHANNEL = 2 ' 0..125 (2.400..2.525GHz)
' --
CLEAR = 1
OBJ
time: "time"
ser: "com.serial.terminal.ansi" | SER_BAUD=115_200
radio: "wireless.transceiver.nrf24l01" | CE=0, CS=1, SCK=2, MOSI=3, MISO=4
VAR
long _ctr_stack[50]
long _iteration, _timer_set
byte _rxdata[PKTLEN]
byte _syncwd[5]
PUB main() | i, iteration, testtime, pipe_nr
setup()
testtime := 1_000 ' mSec
bytemove(@_syncwd, string($E7, $E7, $E7, $E7, $E7), 5)
radio.set_syncwd(@_syncwd) ' set syncword
radio.powered(true)
radio.channel(CHANNEL)
radio.rx_mode()
' Experiment with these to observe effect on throughput
' NOTE: The transmitter's settings _must_ match these
radio.data_rate(2_000_000) ' 250_000, 1_000_000, 2_000_000
radio.auto_ack_pipes_ena(%000011)
radio.tx_pwr(0) ' -18, -12, -6, 0 (dBm)
' (for auto-ack, if enabled)
radio.crc_check_ena(true) ' ignored (always on) if auto-ack is used
radio.crc_len(1) ' 1, 2 (bytes)
repeat pipe_nr from 0 to 5 ' set pipe payload sizes
radio.set_pipe_nr(pipe_nr)
radio.payld_len(PKTLEN) ' _must_ match TX
ser.pos_xy(0, 4)
ser.str(@"Waiting for transmitters on ")
repeat i from 4 to 0 ' show address receiving on
ser.hex(_syncwd[i], 2)
ser.newline()
radio.flush_rx() ' clear rx fifo
radio.int_clear(%100) ' clear interrupt
repeat
iteration := 0
_timer_set := testtime ' trigger the timer
repeat while _timer_set ' loop while timer is >0
repeat until radio.payld_rdy() ' wait for rx data
radio.int_clear(%100) ' _must_ clear interrupt
radio.rx_payld(PKTLEN, @_rxdata) ' retrieve payload
iteration++ ' tally up # payloads rx'd
ser.pos_xy(0, 6)
report(testtime, iteration) ' show the results
PRI cog_counter() | time_left
' Millisecond timer
repeat
repeat until _timer_set ' wait for trigger
time_left := _timer_set
repeat ' ~1ms loop
time_left--
time.msleep(1)
while (time_left > 0)
_timer_set := 0 ' reset timer
PRI report(testtime, iterations) | rate_iterations, rate_bytes, rate_kbits
' Show results of test
rate_iterations := iterations / (testtime/1000) ' # payloads/sec
rate_bytes := (iterations * PKTLEN) / (testtime/1000) ' # bytes/sec
rate_kbits := (rate_bytes * 8) / 1024 ' # kbits/sec
ser.printf4(@"Total iterations: %d, iterations/sec: %d, Bps: %d (%dkbps)", iterations, ...
rate_iterations, ...
rate_bytes, ...
rate_kbits)
ser.clear_line()
PUB setup()
ser.start()
time.msleep(30)
ser.clear()
ser.strln(@"Serial terminal started")
if ( radio.start() )
ser.strln(@"nRF24L01+ driver started")
else
ser.strln(@"nRF24L01+ driver failed to start - halting")
repeat
cognew(cog_counter(), @_ctr_stack)
DAT
{
Copyright 2024 Jesse Burt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}