@@ -105,7 +105,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_t
105
105
*current++ = status;
106
106
}
107
107
} else {
108
- status = RF24_SPI.transfer (*current++);
108
+ ( void ) RF24_SPI.transfer (*current++);
109
109
}
110
110
}
111
111
#endif
@@ -231,9 +231,9 @@ LOCAL uint8_t RF24_getObserveTX(void)
231
231
return RF24_readByteRegister (RF24_REG_OBSERVE_TX);
232
232
}
233
233
234
- LOCAL void RF24_setStatus (const uint8_t status)
234
+ LOCAL uint8_t RF24_setStatus (const uint8_t status)
235
235
{
236
- RF24_writeByteRegister (RF24_REG_STATUS, status);
236
+ return RF24_writeByteRegister (RF24_REG_STATUS, status);
237
237
}
238
238
239
239
LOCAL void RF24_enableFeatures (void )
@@ -307,34 +307,38 @@ LOCAL void RF24_standBy(void)
307
307
LOCAL bool RF24_sendMessage (const uint8_t recipient, const void *buf, const uint8_t len,
308
308
const bool noACK)
309
309
{
310
- uint8_t RF24_status;
311
310
RF24_stopListening ();
312
- RF24_openWritingPipe ( recipient );
313
- RF24_DEBUG (PSTR (" RF24:TXM:TO=%" PRIu8 " ,LEN=%" PRIu8 " \n " ),recipient,len); // send message
311
+ RF24_openWritingPipe (recipient);
312
+ RF24_DEBUG (PSTR (" RF24:TXM:TO=%" PRIu8 " ,LEN=%" PRIu8 " \n " ), recipient, len); // send message
314
313
// flush TX FIFO
315
314
RF24_flushTX ();
315
+ if (noACK) {
316
+ // noACK messages are only sent once
317
+ RF24_setRetries (RF24_SET_ARD, 0 );
318
+ }
316
319
// this command is affected in clones (e.g. Si24R1): flipped NoACK bit when using W_TX_PAYLOAD_NO_ACK / W_TX_PAYLOAD
317
320
// AutoACK is disabled on the broadcasting pipe - NO_ACK prevents resending
318
- RF24_spiMultiByteTransfer ((recipient == RF24_BROADCAST_ADDRESS ||
319
- noACK) ? RF24_CMD_WRITE_TX_PAYLOAD_NO_ACK :
320
- RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t *)buf, len, false );
321
+ (void )RF24_spiMultiByteTransfer (RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t *)buf, len, false );
321
322
// go, TX starts after ~10us, CE high also enables PA+LNA on supported HW
322
323
RF24_ce (HIGH);
323
324
// timeout counter to detect HW issues
324
325
uint16_t timeout = 0xFFFF ;
325
- do {
326
- RF24_status = RF24_getStatus ();
327
- } while (!(RF24_status & ( _BV (RF24_MAX_RT) | _BV (RF24_TX_DS) )) && timeout--);
326
+ while (!( RF24_getStatus () & ( _BV (RF24_MAX_RT) | _BV (RF24_TX_DS))) && timeout--) {
327
+ doYield ();
328
+ }
328
329
// timeout value after successful TX on 16Mhz AVR ~ 65500, i.e. msg is transmitted after ~36 loop cycles
329
330
RF24_ce (LOW);
330
331
// reset interrupts
331
- RF24_setStatus (_BV (RF24_TX_DS) | _BV (RF24_MAX_RT) );
332
+ const uint8_t RF24_status = RF24_setStatus (_BV (RF24_RX_DR) | _BV ( RF24_TX_DS) | _BV (RF24_MAX_RT));
332
333
// Max retries exceeded
333
- if (RF24_status & _BV (RF24_MAX_RT)) {
334
+ if (RF24_status & _BV (RF24_MAX_RT)) {
334
335
// flush packet
335
- RF24_DEBUG (PSTR (" ! RF24:TXM:MAX_RT\n " )); // max retries, no ACK
336
+ RF24_DEBUG (PSTR (" ? RF24:TXM:MAX_RT\n " )); // max retries (normal messages) and noACK messages
336
337
RF24_flushTX ();
337
338
}
339
+ if (noACK) {
340
+ RF24_setRetries (RF24_SET_ARD, RF24_SET_ARC);
341
+ }
338
342
RF24_startListening ();
339
343
// true if message sent
340
344
return (RF24_status & _BV (RF24_TX_DS) || noACK);
@@ -354,17 +358,23 @@ LOCAL uint8_t RF24_getDynamicPayloadSize(void)
354
358
355
359
LOCAL bool RF24_isDataAvailable (void )
356
360
{
357
- return (!(RF24_getFIFOStatus () & _BV (0 )) );
361
+ // prevent debug message flooding
362
+ #if defined(MY_DEBUG_VERBOSE_RF24)
363
+ const uint8_t value = RF24_spiMultiByteTransfer (RF24_CMD_READ_REGISTER | (RF24_REGISTER_MASK &
364
+ (RF24_REG_FIFO_STATUS)), NULL , 1 , true );
365
+ return (bool )(!(value & _BV (RF24_RX_EMPTY)));
366
+ #else
367
+ return (bool )(!(RF24_getFIFOStatus () & _BV (RF24_RX_EMPTY)) );
368
+ #endif
358
369
}
359
370
360
-
361
371
LOCAL uint8_t RF24_readMessage (void *buf)
362
372
{
363
373
const uint8_t len = RF24_getDynamicPayloadSize ();
364
374
RF24_DEBUG (PSTR (" RF24:RXM:LEN=%" PRIu8 " \n " ), len); // read message
365
- RF24_spiMultiByteTransfer (RF24_CMD_READ_RX_PAYLOAD,(uint8_t *)buf,len,true );
375
+ RF24_spiMultiByteTransfer (RF24_CMD_READ_RX_PAYLOAD, (uint8_t *)buf, len, true );
366
376
// clear RX interrupt
367
- RF24_setStatus (_BV (RF24_RX_DR));
377
+ ( void ) RF24_setStatus (_BV (RF24_RX_DR));
368
378
return len;
369
379
}
370
380
0 commit comments