Skip to content

Commit 6745f03

Browse files
committed
modify streamingData and IRQconfig examples
1 parent f688cad commit 6745f03

File tree

8 files changed

+182
-81
lines changed

8 files changed

+182
-81
lines changed

examples/InterruptConfigure/InterruptConfigure.ino

+35-19
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ uint8_t pl_iterator = 0;
4949
char tx_payloads[][tx_pl_size + 1] = { "Ping ", "Pong ", "Radio", "1FAIL" };
5050
char ack_payloads[][ack_pl_size + 1] = { "Yak ", "Back", " ACK" };
5151

52+
// A variable to interpret and manipulate the radio's IRQ pin.
53+
StatusFlags flags;
54+
5255
void interruptHandler(); // prototype to handle IRQ events
5356
void printRxFifo(); // prototype to print RX FIFO with 1 buffer
5457

@@ -150,21 +153,31 @@ void loop() {
150153
// Test the "data ready" event with the IRQ pin
151154

152155
Serial.println(F("\nConfiguring IRQ pin to ignore the 'data sent' event"));
153-
radio.maskIRQ(true, false, false); // args = "data_sent", "data_fail", "data_ready"
156+
flags.rx_dr = true;
157+
flags.tx_ds = false;
158+
flags.tx_df = true;
159+
radio.setStatusFlags(flags);
154160
Serial.println(F(" Pinging RX node for 'data ready' event..."));
155161

156162
} else if (pl_iterator == 1) {
157163
// Test the "data sent" event with the IRQ pin
158164

159165
Serial.println(F("\nConfiguring IRQ pin to ignore the 'data ready' event"));
160-
radio.maskIRQ(false, false, true); // args = "data_sent", "data_fail", "data_ready"
166+
flags.rx_dr = false;
167+
flags.tx_ds = true;
168+
flags.tx_df = true;
169+
radio.setStatusFlags(flags);
161170
Serial.println(F(" Pinging RX node for 'data sent' event..."));
162171

163172
} else if (pl_iterator == 2) {
164173
// Use this iteration to fill the RX node's FIFO which sets us up for the next test.
165174

166175
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin
167-
radio.maskIRQ(1, 1, 1); // disable IRQ masking for this step
176+
// disable IRQ pin for this step
177+
flags.rx_dr = false;
178+
flags.tx_ds = false;
179+
flags.tx_df = false;
180+
radio.setStatusFlags(flags);
168181

169182
Serial.println(F("\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected."));
170183
// write() will call flush_tx() on 'data fail' events
@@ -183,7 +196,10 @@ void loop() {
183196
// test the "data fail" event with the IRQ pin
184197

185198
Serial.println(F("\nConfiguring IRQ pin to reflect all events"));
186-
radio.maskIRQ(0, 0, 0); // args = "data_sent", "data_fail", "data_ready"
199+
flags.rx_dr = true;
200+
flags.tx_ds = true;
201+
flags.tx_df = true;
202+
radio.setStatusFlags(flags);
187203
Serial.println(F(" Pinging inactive RX node for 'data fail' event..."));
188204
}
189205

@@ -266,7 +282,11 @@ void loop() {
266282

267283
role = false;
268284

269-
radio.maskIRQ(0, 0, 0); // the IRQ pin should only trigger on "data ready" event
285+
// let IRQ pin only trigger on "data_ready" event in RX mode
286+
flags.rx_dr = true;
287+
flags.tx_ds = false;
288+
flags.tx_df = false;
289+
radio.setStatusFlags(flags);
270290

271291
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
272292
// transmissions on pipe 1
@@ -298,33 +318,29 @@ void assessInterruptEvent() {
298318

299319
Serial.println(F("\tIRQ pin is actively LOW")); // show that this function was called
300320
delayMicroseconds(250);
301-
bool tx_ds, tx_df, rx_dr; // declare variables for IRQ masks
302-
radio.whatHappened(tx_ds, tx_df, rx_dr); // get values for IRQ masks
303-
// whatHappened() clears the IRQ masks also. This is required for
321+
StatusFlags status = radio.clearStatusFlags();
322+
// Resetting the tx_df flag is required for
304323
// continued TX operations when a transmission fails.
305-
// clearing the IRQ masks resets the IRQ pin to its inactive state (HIGH)
324+
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)
306325

307-
Serial.print(F("\tdata_sent: "));
308-
Serial.print(tx_ds); // print "data sent" mask state
309-
Serial.print(F(", data_fail: "));
310-
Serial.print(tx_df); // print "data fail" mask state
311-
Serial.print(F(", data_ready: "));
312-
Serial.println(rx_dr); // print "data ready" mask state
326+
char buf[69];
327+
status.toString(buf);
328+
Serial.println(buf); // print "status flags info
313329

314-
if (tx_df) // if TX payload failed
330+
if (status.tx_df) // if TX payload failed
315331
radio.flush_tx(); // clear all payloads from the TX FIFO
316332

317333
// print if test passed or failed. Unintentional fails mean the RX node was not listening.
318334
// pl_iterator has already been incremented by now
319335
if (pl_iterator <= 1) {
320336
Serial.print(F(" 'Data Ready' event test "));
321-
Serial.println(rx_dr ? F("passed") : F("failed"));
337+
Serial.println(status.rx_dr ? F("passed") : F("failed"));
322338
} else if (pl_iterator == 2) {
323339
Serial.print(F(" 'Data Sent' event test "));
324-
Serial.println(tx_ds ? F("passed") : F("failed"));
340+
Serial.println(status.tx_ds ? F("passed") : F("failed"));
325341
} else if (pl_iterator == 4) {
326342
Serial.print(F(" 'Data Fail' event test "));
327-
Serial.println(tx_df ? F("passed") : F("failed"));
343+
Serial.println(status.tx_df ? F("passed") : F("failed"));
328344
}
329345
got_interrupt = false; // reset this flag to prevent calling this function from loop()
330346
wait_for_event = false; // ready to continue with loop() operations

examples/StreamingData/StreamingData.ino

+10-2
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,23 @@ void loop() {
106106
if (role) {
107107
// This device is a TX node
108108

109+
StatusFlags flags;
109110
radio.flush_tx();
110111
uint8_t i = 0;
111112
uint8_t failures = 0;
112113
unsigned long start_timer = micros(); // start the timer
113114
while (i < SIZE) {
114115
makePayload(i); // make the payload
115116
if (!radio.writeFast(&buffer, SIZE)) {
116-
failures++;
117-
radio.reUseTX();
117+
radio.getStatusFlags(flags);
118+
if (flags.tx_df) {
119+
failures++;
120+
// now we need to reset the tx_df flag and the radio's CE pin
121+
radio.ce(LOW);
122+
radio.clearStatusFlags(flags);
123+
radio.ce(HIGH);
124+
}
125+
// else the TX FIFO is full; just continue loop.
118126
} else {
119127
i++;
120128
}

examples_linux/interruptConfigure.cpp

+36-19
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ uint8_t pl_iterator = 0;
6363
char tx_payloads[4][tx_pl_size + 1] = {"Ping ", "Pong ", "Radio", "1FAIL"};
6464
char ack_payloads[3][ack_pl_size + 1] = {"Yak ", "Back", " ACK"};
6565

66+
// A variable used to interpret and manipulate the IRQ pin.
67+
StatusFlags flags;
68+
6669
void interruptHandler(); // prototype to handle the interrupt request (IRQ) pin
6770
void setRole(); // prototype to set the node's role
6871
void master(); // prototype of the TX node's behavior
@@ -158,7 +161,7 @@ void setRole()
158161
cout << input[0] << " is an invalid input. Please try again." << endl;
159162
}
160163
input = ""; // stay in the while loop
161-
} // while
164+
} // while
162165
} // setRole
163166

164167
/**
@@ -174,22 +177,32 @@ void master()
174177

175178
// Test the "data ready" event with the IRQ pin
176179
cout << "\nConfiguring IRQ pin to ignore the 'data sent' event\n";
177-
radio.maskIRQ(true, false, false); // args = "data_sent", "data_fail", "data_ready"
180+
flags.rx_dr = true;
181+
flags.tx_ds = false;
182+
flags.tx_df = true;
183+
radio.setStatusFlags(flags);
178184
cout << " Pinging RX node for 'data ready' event..." << endl;
179185
ping_n_wait(); // transmit a payload and detect the IRQ pin
180186
pl_iterator++; // increment iterator for next test
181187

182188
// Test the "data sent" event with the IRQ pin
183189
cout << "\nConfiguring IRQ pin to ignore the 'data ready' event\n";
184-
radio.maskIRQ(false, false, true); // args = "data_sent", "data_fail", "data_ready"
190+
flags.rx_dr = false;
191+
flags.tx_ds = true;
192+
flags.tx_df = true;
193+
radio.setStatusFlags(flags);
185194
cout << " Pinging RX node for 'data sent' event..." << endl;
186195
radio.flush_tx(); // flush payloads from any failed prior test
187196
ping_n_wait(); // transmit a payload and detect the IRQ pin
188197
pl_iterator++; // increment iterator for next test
189198

190199
// Use this iteration to fill the RX node's FIFO which sets us up for the next test.
191-
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin
192-
radio.maskIRQ(1, 1, 1); // disable IRQ masking for this step
200+
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin.
201+
// disable IRQ pin for this step
202+
flags.rx_dr = false;
203+
flags.tx_ds = false;
204+
flags.tx_df = false;
205+
radio.setStatusFlags(flags);
193206

194207
cout << "\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected.\n";
195208
// write() will call flush_tx() on 'data fail' events
@@ -203,7 +216,10 @@ void master()
203216

204217
// test the "data fail" event with the IRQ pin
205218
cout << "\nConfiguring IRQ pin to reflect all events\n";
206-
radio.maskIRQ(0, 0, 0); // args = "data_sent", "data_fail", "data_ready"
219+
flags.rx_dr = true;
220+
flags.tx_ds = true;
221+
flags.tx_df = true;
222+
radio.setStatusFlags(flags);
207223
cout << " Pinging inactive RX node for 'data fail' event..." << endl;
208224
ping_n_wait(); // transmit a payload and detect the IRQ pin
209225

@@ -223,7 +239,10 @@ void slave()
223239
{
224240

225241
// let IRQ pin only trigger on "data_ready" event in RX mode
226-
radio.maskIRQ(1, 1, 0); // args = "data_sent", "data_fail", "data_ready"
242+
flags.rx_dr = true;
243+
flags.tx_ds = false;
244+
flags.tx_df = false;
245+
radio.setStatusFlags(flags);
227246

228247
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
229248
// transmissions on pipe 0.
@@ -277,26 +296,24 @@ void ping_n_wait()
277296

278297
cout << "\tIRQ pin is actively LOW" << endl; // show that this function was called
279298

280-
bool tx_ds, tx_df, rx_dr; // declare variables for IRQ masks
281-
radio.whatHappened(tx_ds, tx_df, rx_dr); // get values for IRQ masks
282-
// whatHappened() clears the IRQ masks also. This is required for
299+
StatusFlags status = radio.clearStatusFlags();
300+
// Resetting the tx_df flag is required for
283301
// continued TX operations when a transmission fails.
284-
// clearing the IRQ masks resets the IRQ pin to its inactive state (HIGH)
285-
286-
cout << "\tdata_sent: " << tx_ds; // print "data sent" mask state
287-
cout << ", data_fail: " << tx_df; // print "data fail" mask state
288-
cout << ", data_ready: " << rx_dr << endl; // print "data ready" mask state
302+
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)
303+
char buf[69];
304+
status.toString(buf);
305+
cout << "\t" << buf << endl; // print StatusFlags description
289306

290-
if (tx_df) // if TX payload failed
307+
if (status.tx_df) // if TX payload failed
291308
radio.flush_tx(); // clear all payloads from the TX FIFO
292309

293310
// print if test passed or failed. Unintentional fails mean the RX node was not listening.
294311
if (pl_iterator == 0)
295-
cout << " 'Data Ready' event test " << (rx_dr ? "passed" : "failed") << endl;
312+
cout << " 'Data Ready' event test " << (status.rx_dr ? "passed" : "failed") << endl;
296313
else if (pl_iterator == 1)
297-
cout << " 'Data Sent' event test " << (tx_ds ? "passed" : "failed") << endl;
314+
cout << " 'Data Sent' event test " << (status.tx_ds ? "passed" : "failed") << endl;
298315
else if (pl_iterator == 3)
299-
cout << " 'Data Fail' event test " << (tx_df ? "passed" : "failed") << endl;
316+
cout << " 'Data Fail' event test " << (status.tx_df ? "passed" : "failed") << endl;
300317

301318
got_interrupt = false;
302319
}

examples_linux/interrupt_configure.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import time
9-
from RF24 import RF24, RF24_PA_LOW, RF24_DRIVER
9+
from RF24 import RF24, RF24_PA_LOW, RF24_DRIVER, StatusFlags
1010

1111
try:
1212
import gpiod
@@ -93,18 +93,24 @@
9393
tx_payloads = (b"Ping ", b"Pong ", b"Radio", b"1FAIL")
9494
ack_payloads = (b"Yak ", b"Back", b" ACK")
9595

96+
# a variable used interpret and manipulate the IRQ pin
97+
flags = StatusFlags()
98+
9699

97100
def interrupt_handler():
98101
"""This function is called when IRQ pin is detected active LOW"""
99102
print("\tIRQ pin went active LOW.")
100-
tx_ds, tx_df, rx_dr = radio.whatHappened() # update IRQ status flags
101-
print(f"\ttx_ds: {tx_ds}, tx_df: {tx_df}, rx_dr: {rx_dr}")
103+
flags = radio.clearStatusFlags()
104+
# Resetting the tx_df flag is required for
105+
# continued TX operations when a transmission fails.
106+
# clearing the status flags resets the IRQ pin to its inactive state (HIGH)
107+
print(f"\t{flags}")
102108
if pl_iterator[0] == 0:
103-
print(" 'data ready' event test", ("passed" if rx_dr else "failed"))
109+
print(" 'data ready' event test", ("passed" if flags.rx_dr else "failed"))
104110
elif pl_iterator[0] == 1:
105-
print(" 'data sent' event test", ("passed" if tx_ds else "failed"))
111+
print(" 'data sent' event test", ("passed" if flags.tx_ds else "failed"))
106112
elif pl_iterator[0] == 2:
107-
print(" 'data fail' event test", ("passed" if tx_df else "failed"))
113+
print(" 'data fail' event test", ("passed" if flags.tx_df else "failed"))
108114

109115

110116
# setup IRQ GPIO pin
@@ -143,7 +149,10 @@ def master():
143149

144150
# on data ready test
145151
print("\nConfiguring IRQ pin to only ignore 'on data sent' event")
146-
radio.maskIRQ(True, False, False) # args = tx_ds, tx_df, rx_dr
152+
flags.tx_df = True
153+
flags.tx_ds = False
154+
flags.rx_dr = True
155+
radio.setStatusFlags(flags)
147156
print(" Pinging slave node for an ACK payload...")
148157
pl_iterator[0] = 0
149158
radio.startFastWrite(tx_payloads[0], False) # False means expecting an ACK
@@ -152,7 +161,10 @@ def master():
152161

153162
# on "data sent" test
154163
print("\nConfiguring IRQ pin to only ignore 'on data ready' event")
155-
radio.maskIRQ(False, False, True) # args = tx_ds, tx_df, rx_dr
164+
flags.tx_df = True
165+
flags.tx_ds = True
166+
flags.rx_dr = False
167+
radio.setStatusFlags(flags)
156168
print(" Pinging slave node again...")
157169
pl_iterator[0] = 1
158170
radio.startFastWrite(tx_payloads[1], False) # False means expecting an ACK
@@ -162,15 +174,21 @@ def master():
162174
# trigger slave node to exit by filling the slave node's RX FIFO
163175
print("\nSending one extra payload to fill RX FIFO on slave node.")
164176
print("Disabling IRQ pin for all events.")
165-
radio.maskIRQ(True, True, True) # args = tx_ds, tx_df, rx_dr
177+
flags.tx_df = False
178+
flags.tx_ds = False
179+
flags.rx_dr = False
180+
radio.setStatusFlags(flags)
166181
if radio.write(tx_payloads[2]):
167182
print("Slave node should not be listening anymore.")
168183
else:
169184
print("Slave node was unresponsive.")
170185

171186
# on "data fail" test
172187
print("\nConfiguring IRQ pin to go active for all events.")
173-
radio.maskIRQ(False, False, False) # args = tx_ds, tx_df, rx_dr
188+
flags.tx_df = True
189+
flags.tx_ds = True
190+
flags.rx_dr = True
191+
radio.setStatusFlags(flags)
174192
print(" Sending a ping to inactive slave node...")
175193
radio.flush_tx() # just in case any previous tests failed
176194
pl_iterator[0] = 2
@@ -189,7 +207,10 @@ def slave(timeout=6): # will listen for 6 seconds before timing out
189207
# the "data sent" or "data fail" events will trigger when we
190208
# receive with ACK payloads enabled (& loaded in TX FIFO)
191209
print("\nDisabling IRQ pin for all events.")
192-
radio.maskIRQ(True, True, True) # args = tx_ds, tx_df, rx_dr
210+
flags.tx_df = False
211+
flags.tx_ds = False
212+
flags.rx_dr = False
213+
radio.setStatusFlags(flags)
193214
# setup radio to receive pings, fill TX FIFO with ACK payloads
194215
radio.writeAckPayload(1, ack_payloads[0])
195216
radio.writeAckPayload(1, ack_payloads[1])

0 commit comments

Comments
 (0)