support for auto ACK and retransmissions added

Dependents:   JNP3_IOT_6_RADIO_ECHO_FIXED nRF24L01P_NET_GW nRF24L01P_NET_SENSOR Kubus ... more

Fork of nRF24L01P by Owen Edwards

Files at this revision

API Documentation at this revision

Comitter:
ttajmajer
Date:
Tue Nov 15 15:47:58 2016 +0000
Parent:
0:8ae48233b4e4
Child:
2:3012f09dfcc2
Commit message:
fixed problems with auto ack and retransmissions

Changed in this revision

nRF24L01P.cpp Show annotated file Show diff for this revision Revisions of this file
nRF24L01P.h Show annotated file Show diff for this revision Revisions of this file
--- a/nRF24L01P.cpp	Wed Jan 19 22:59:48 2011 +0000
+++ b/nRF24L01P.cpp	Tue Nov 15 15:47:58 2016 +0000
@@ -555,6 +555,18 @@
 
 }
 
+void nRF24L01P::enableAutoRetransmit(int delay, int count) {
+	delay = (0x00F0 & (delay << 4));
+	count = (0x000F & count);
+
+	setRegister(_NRF24L01P_REG_SETUP_RETR, delay|count);
+
+}
+
+int nRF24L01P::getRetrCount(){
+	return getRegister(_NRF24L01P_REG_OBSERVE_TX) & 0x0F;
+}
+
 void nRF24L01P::setRxAddress(unsigned long long address, int width, int pipe) {
 
     if ( ( pipe < NRF24L01P_PIPE_P0 ) || ( pipe > NRF24L01P_PIPE_P5 ) ) {
@@ -835,6 +847,8 @@
 
 
 int nRF24L01P::write(int pipe, char *data, int count) {
+	
+	Timer timeout;
 
     // Note: the pipe number is ignored in a Transmit / write
 
@@ -870,14 +884,20 @@
     wait_us(_NRF24L01P_TIMING_Thce_us);
     disable();
 
-    while ( !( getStatusRegister() & _NRF24L01P_STATUS_TX_DS ) ) {
-
-        // Wait for the transfer to complete
+	//timeout.start();
+    while ( !( getStatusRegister() & (_NRF24L01P_STATUS_TX_DS | _NRF24L01P_STATUS_MAX_RT) ) ) {
 
     }
+    //timeout.stop();
+    //timeout.reset();
+    
+    if(getStatusRegister() & _NRF24L01P_STATUS_MAX_RT)
+    	count = -1;
+    
 
     // Clear the Status bit
     setRegister(_NRF24L01P_REG_STATUS, _NRF24L01P_STATUS_TX_DS);
+    setRegister(_NRF24L01P_REG_STATUS, _NRF24L01P_STATUS_MAX_RT);
 
     if ( originalMode == _NRF24L01P_MODE_RX ) {
 
--- a/nRF24L01P.h	Wed Jan 19 22:59:48 2011 +0000
+++ b/nRF24L01P.h	Tue Nov 15 15:47:58 2016 +0000
@@ -219,6 +219,13 @@
      * @return true if the received power exceeded -64dBm
      */
     bool getRPD(void);
+    
+    /**
+     * Get the ARC_CNT register value
+     *
+     * @return number of retransmissions
+     */
+    int getRetrCount(void);
 
     /**
      * Put the nRF24L01+ into Receive mode