nRF24L01 driver

Dependents:   Nucleo_IOT1 wireless

Revision:
4:8f612189af31
Parent:
0:7313e63394c3
Child:
5:bb28775120e7
--- 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