-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNRF24L01-SpeedTest-RX.spin2
154 lines (114 loc) · 5.64 KB
/
NRF24L01-SpeedTest-RX.spin2
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
147
148
149
150
151
152
153
{
----------------------------------------------------------------------------------------------------
Filename: NRF24L01-SpeedTest-RX.spin2
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.
----------------------------------------------------------------------------------------------------
}
#include "core.con.click.spin2"
CON
_clkfreq = 180_000_000
_xtlfreq = 20_000_000
' -- User-modifiable constants
CLICK_BASE = 0 ' 0, 16, 32, 48
PKTLEN = 32 ' 1..32 (bytes)
CHANNEL = 2 ' 0..125 (2.400..2.525GHz)
' --
CLEAR = 1
OBJ
ser: "com.serial.terminal.ansi" | SER_BAUD=2_000_000
{ use with MikroE Click boards - define the CLICK_BASE I/O pin above and leave these as-is }
radio: "wireless.transceiver.nrf24l01" | CE=RES_PIN, CS=CS_PIN, SCK=SCK_PIN, MOSI=MOSI_PIN, MISO=MISO_PIN, SPI_FREQ=10_000_000
{ use custom I/O pins; comment out the line above and uncomment this one }
' radio: "wireless.transceiver.nrf24l01" | CE=0, CS=1, SCK=2, MOSI=3, MISO=4, SPI_FREQ=10_000_000
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--
waitms(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.printf(@"Total iterations: %d, iterations/sec: %d, Bps: %d (%dkbps)", iterations, ...
rate_iterations, ...
rate_bytes, ...
rate_kbits)
ser.clear_line()
PUB setup()
ser.start()
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
cogspin(NEWCOG, 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.
}