Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Nucleo_IOT1 wireless
Revision 4:8f612189af31, committed 2016-09-03
- Comitter:
- ianmcc
- Date:
- Sat Sep 03 12:24:04 2016 +0000
- Parent:
- 3:39e8335cce5d
- Child:
- 5:bb28775120e7
- Commit message:
- Fix handling of blocking transmit, no need to use the interrupt handler
Changed in this revision
--- a/nRF24L01P.cpp Fri Sep 02 15:51:22 2016 +0000
+++ b/nRF24L01P.cpp Sat Sep 03 12:24:04 2016 +0000
@@ -274,6 +274,15 @@
void
nRF24L01P::set_retransmit_delay(int Delay)
{
+ char c = this->read_register(NRF24L01P_SETUP_RETR);
+ this->write_register(NRF24L01P_SETUP_RETR, (c & 0x0f) | ((Delay & 0x0f) << 4));
+}
+
+void
+nRF24L01P::set_retransmit_attempts(int Attempts)
+{
+ char c = this->read_register(NRF24L01P_SETUP_RETR);
+ this->write_register(NRF24L01P_SETUP_RETR, (c & 0xf0) | (Attempts & 0x0f));
}
bool
--- a/nRF24L01P.h Fri Sep 02 15:51:22 2016 +0000
+++ b/nRF24L01P.h Sat Sep 03 12:24:04 2016 +0000
@@ -47,7 +47,7 @@
// set the RF channel, 0 .. 125.
// The frequency in MHz is 2400 + Channel.
// In 2Mbps mode, you must use channels at least 2MHz appart to avoid overlap
- // DEFAULT:
+ // DEFAULT: channel 2
void set_channel(int Channel);
// PRECONDITION: Mode = Receive. True if a signal higher than -64bB is detected by the receiver
@@ -59,11 +59,11 @@
// enable or disable dynamic payload size on the given pipe
- // DEFAULT:
+ // DEFAULT: false
void enable_dynamic_payload(int Pipe, bool Enable);
// Enable including a payload with ACK
- // DEFAULT:
+ // DEFAULT: false
void enable_ack_payload(bool Enable);
// enable the write_tx_payload_no_ack() command
@@ -138,11 +138,11 @@
// set the auto-retransmit delay, in units of 250 microseconds.
// Valid input is 0,1,...,15 (for 250 .. 4000 us)
- // DEFAULT:
+ // DEFAULT: 0 (250us)
void set_retransmit_delay(int Delay);
// set the number of auto-retransmit attempts, 0 .. 15
- // DEFAULT:
+ // DEFAULT: 3
void set_retransmit_attempts(int Attempts);
// returns true if we've hit the maximum number of restransmits
@@ -156,11 +156,11 @@
void set_interrupt_max_rt(bool Enable);
// enable or disable the CRC check. Auto-acknowledge forces CRC enabled.
- // DEFAULT:
+ // DEFAULT: true
void enable_crc(bool Enable);
// set the CRC width, either 1 byte or 2 bytes
- // DEFAULT:
+ // DEFAULT: 1 byte
void set_crc_width(int width);
// set PWR_UP (move into standby mode)
@@ -198,7 +198,7 @@
// Set the tx address. Used only for a PTX, set this the same as the rx_address of pipe 0 to enable
// auto-acknowledge with Enhanced ShockBurst(TM)
- // DEFAULT:
+ // DEFAULT: 0xE7E7E7E7E
void set_tx_address(uint64_t Address);
// commands
--- a/nRF24L01P_PTX.cpp Fri Sep 02 15:51:22 2016 +0000
+++ b/nRF24L01P_PTX.cpp Sat Sep 03 12:24:04 2016 +0000
@@ -120,16 +120,29 @@
while (Status == STATUS_TRANSMITTING)
{
wait_us(1);
+ if (Device.is_tx_sent())
+ {
+ // we successfully sent a packet
+ Status = STATUS_PACKET_OK;
+ Device.clear_tx_sent();
+ }
+ else if (Device.is_max_rt())
+ {
+ // we failed to send the packet
+ Status = STATUS_PACKET_MAX_RT;
+ Device.clear_max_rt();
+ }
}
- int OldStatus = Status;
- if (OldStatus == STATUS_PACKET_OK)
+
+ if (Status == STATUS_PACKET_OK)
{
Status = STATUS_STANDBY;
return 0;
}
- else if (OldStatus == STATUS_PACKET_MAX_RT)
+ else if (Status == STATUS_PACKET_MAX_RT)
{
Status = STATUS_STANDBY;
+ Device.flush_tx_fifo();
return -1;
}
// else the Status isn't what we expected, which
@@ -141,18 +154,6 @@
void
nRF24L01P_PTX::IntHandler()
{
- if (Device.is_tx_sent())
- {
- // we successfully sent a packet
- Status = STATUS_PACKET_OK;
- Device.clear_tx_sent();
- }
- else if (Device.is_max_rt())
- {
- // we failed to send the packet
- Status = STATUS_PACKET_MAX_RT;
- Device.clear_max_rt();
- }
}
void