Krolyxon
Commit 1d55752

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8RF24examplesencodeRadioDetailsencodeRadioDetails.ino

123 lines · 3.7 KB

1/*
2 See documentation at https://nRF24.github.io/RF24
3 See License information at root directory of this library
4 Authors: Brendan Doherty (2bndy5), Douglas Quigg (dstroy0)
5*/
6
7/**
8 A simple example of getting debug info from the nRF24L01 transceiver.
9
10 This example was written to demonstrate alternative methods to get debugging data.
11 1. radio.encodeRadioDetails() will provide a data dump of all the nRF24L01's registers.
12 2. radio.sprintfPrettyDetails() will behave similarly to printPrettyDetails(), but it
13 outputs to a char buffer that can be printed to any Serial (or other output) stream.
14
15 Additionally, this example will show all default configuration values.
16*/
17#include <SPI.h>
18#include "RF24.h"
19
20#define CE_PIN 7
21#define CSN_PIN 8
22// instantiate an object for the nRF24L01 transceiver
23RF24 radio(CE_PIN, CSN_PIN);
24
25/*
26 For this example, we'll be using a data buffer containing
27 radio details encoded with RF24::encodeRadioDetails().
28 It is meant to be decoded by an external program.
29
30 There is a python script located in this example's folder that
31 will take a space-delimited string of hexadecimal characters and
32 decode then print it out as human readable information.
33*/
34uint8_t encoded_details[43] = { 0 };
35
36// Use this function to print out the encoded_details as a
37// space-delimited string of hexadecimal characters.
38void dumpRegData() {
39 for (uint8_t i = 0; i < 43; ++i) {
40 Serial.print(encoded_details[i], HEX);
41 if (i < 42)
42 Serial.print(F(" "));
43 }
44}
45
46void setup() {
47
48 Serial.begin(115200);
49 while (!Serial) {
50 // some boards need to wait to ensure access to serial over USB
51 }
52
53 // initialize the transceiver on the SPI bus
54 if (!radio.begin()) {
55 Serial.println(F("radio hardware is not responding!!"));
56 while (1) {} // hold in infinite loop
57 }
58
59 // print example's introductory prompt
60 Serial.println(F("RF24/examples/encodedRadioDetails"));
61
62 Serial.println(F("Press any key to show debugging information"));
63 while (!Serial.available()) {
64 // wait for user input
65 }
66
67 // For debugging info
68 char *debug_info = new char[870];
69 uint16_t str_len = radio.sprintfPrettyDetails(debug_info);
70 Serial.println(debug_info);
71 Serial.print(F("\nThe above output used "));
72 Serial.print(str_len);
73 Serial.println(F(" characters."));
74
75 // encoded_details is NOT human readable.
76 // encodeRadioDetails() is very small when used on its own because it puts debugging information into a byte array
77 // No printf() support needed because it doesn't use an output stream.
78 radio.encodeRadioDetails(encoded_details);
79 Serial.println(F("\nhexadecimal dump of all registers:"));
80 dumpRegData();
81
82 Serial.println(F("\n\nCopy the above string of hexadecimal characters (including spaces)."));
83 Serial.print(F("Then paste it into a terminal using the print_details.py located in"));
84 Serial.print(F(" this example's folder. Like so:\npython print_details.py \""));
85 dumpRegData();
86 Serial.println(F("\"\n***You may need to use 'python3' (without quotes) on Linux"));
87} // setup
88
89/* Registers corresponding to index of encoded_details array
90 0: NRF_CONFIG
91 1: EN_AA
92 2: EN_RXADDR
93 3: SETUP_AW
94 4: SETUP_RETR
95 5: RF_CH
96 6: RF_SETUP
97 7: NRF_STATUS
98 8: OBSERVE_TX
99 9: CD (aka RPD)
100 10-14: RX_ADDR_P0
101 15-19: RX_ADDR_P1
102 20: RX_ADDR_P2
103 21: RX_ADDR_P3
104 22: RX_ADDR_P4
105 23: RX_ADDR_P5
106 24-28: TX_ADDR
107 29: RX_PW_P0
108 30: RX_PW_P1
109 31: RX_PW_P2
110 32: RX_PW_P3
111 33: RX_PW_P4
112 34: RX_PW_P5
113 35: FIFO_STATUS
114 36: DYNPD
115 37: FEATURE
116 38-39: ce_pin
117 40-41: csn_pin
118 42: SPI speed MHz | (isPlusVariant << 4)
119*/
120
121void loop() {
122 // Nothing to do here. We did it all at the end of setup()
123}