Kenny Huang / nRF24L01

Dependents:   HexiComm HexiwearAlertSystem Hexi

Fork of nRF24L01P by Owen Edwards

Files at this revision

API Documentation at this revision

Comitter:
khuang
Date:
Wed Oct 05 06:02:50 2016 +0000
Parent:
0:8ae48233b4e4
Commit message:
Added flush tx and rx to startup sequence;

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	Wed Oct 05 06:02:50 2016 +0000
@@ -178,17 +178,19 @@
                      PinName ce,
                      PinName irq) : spi_(mosi, miso, sck), nCS_(csn), ce_(ce), nIRQ_(irq) {
 
-    mode = _NRF24L01P_MODE_UNKNOWN;
-
-    disable();
-
+   
     nCS_ = 1;
 
     spi_.frequency(_NRF24L01P_SPI_MAX_DATA_RATE/5);     // 2Mbit, 1/5th the maximum transfer rate for the SPI bus
     spi_.format(8,0);                                   // 8-bit, ClockPhase = 0, ClockPolarity = 0
+}
 
+void	nRF24L01P::init(void)
+{
+ 	mode = _NRF24L01P_MODE_UNKNOWN;
+    disable();
     wait_us(_NRF24L01P_TIMING_Tundef2pd_us);    // Wait for Power-on reset
-
+    
     setRegister(_NRF24L01P_REG_CONFIG, 0); // Power Down
 
     setRegister(_NRF24L01P_REG_STATUS, _NRF24L01P_STATUS_MAX_RT|_NRF24L01P_STATUS_TX_DS|_NRF24L01P_STATUS_RX_DR);   // Clear any pending interrupts
@@ -206,6 +208,11 @@
     disableAutoAcknowledge();
     disableAutoRetransmit();
     setTransferSize();
+    
+    nCS_ = 0;
+    spi_.write(_NRF24L01P_SPI_CMD_FLUSH_TX);
+    spi_.write(_NRF24L01P_SPI_CMD_FLUSH_RX);
+    nCS_ = 1;
 
     mode = _NRF24L01P_MODE_POWER_DOWN;
 
@@ -1027,3 +1034,32 @@
     return status;
 
 }
+
+bool nRF24L01P::getRPD(){
+    uint8_t rpd = getRegister(_NRF24L01P_REG_RPD);
+    return (rpd>0);
+}
+
+uint8_t nRF24L01P::getRSSI(){
+    uint8_t rssi =0;
+    for(int i=0; i<256; i++){
+        rssi += getRPD();
+        Thread::wait(50);
+        flushRx();
+    }
+    return rssi;
+}
+
+void nRF24L01P::flushRx(void)
+{
+    nCS_ = 0;
+    spi_.write(_NRF24L01P_SPI_CMD_FLUSH_RX);
+    nCS_ = 1;
+}
+
+void nRF24L01P::flushTx(void)
+{
+    nCS_ = 0;
+    spi_.write(_NRF24L01P_SPI_CMD_FLUSH_TX);
+    nCS_ = 1;
+}
--- a/nRF24L01P.h	Wed Jan 19 22:59:48 2011 +0000
+++ b/nRF24L01P.h	Wed Oct 05 06:02:50 2016 +0000
@@ -309,6 +309,14 @@
      * @param count number of retransmits before generating an error (1..15)
      */
     void enableAutoRetransmit(int delay, int count);
+    
+    void init(void);
+    
+    uint8_t getRSSI(void);
+    void flushRx(void);
+    void flushTx(void);
+
+
 
 private: