nRF24 test hello

Dependents:   stm32_hello_nrf24 commu4 commu4-2 commu4 ... more

Files at this revision

API Documentation at this revision

Comitter:
hakusan270
Date:
Sat Nov 28 13:58:50 2020 +0000
Parent:
3:7606e50461e1
Commit message:
reset issue

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
diff -r 7606e50461e1 -r d3349b4b6496 nRF24L01P.cpp
--- a/nRF24L01P.cpp	Sat Nov 28 07:13:12 2020 +0000
+++ b/nRF24L01P.cpp	Sat Nov 28 13:58:50 2020 +0000
@@ -181,15 +181,40 @@
     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
-
     wait_us(_NRF24L01P_TIMING_Tundef2pd_us);    // Wait for Power-on reset
+/******** Reset ************/
+    setRegister(_NRF24L01P_REG_CONFIG, 0x08); // Power Down
+    flush_tx_fifo();
+    flush_rx_fifo();
+    setRegister(_NRF24L01P_REG_EN_AA,         0x3F);
+    setRegister(_NRF24L01P_REG_EN_RXADDR,     0x03);
+    setRegister(_NRF24L01P_REG_SETUP_AW,      0x03);
+    setRegister(_NRF24L01P_REG_SETUP_RETR,    0x03);
+    setRegister(_NRF24L01P_REG_RF_CH,         0x02);
+    setRegister(_NRF24L01P_REG_RF_SETUP,      0x07);
+    setRegister(_NRF24L01P_REG_STATUS,        0x0E); 
+    setRegister(_NRF24L01P_REG_RX_ADDR_P2,    0xC3);
+    setRegister(_NRF24L01P_REG_RX_ADDR_P3,    0xC4);
+    setRegister(_NRF24L01P_REG_RX_ADDR_P4,    0xC4);
+    setRegister(_NRF24L01P_REG_RX_ADDR_P5,    0xC5);
+    setRegister(_NRF24L01P_REG_RX_PW_P0,      0x00);
+    setRegister(_NRF24L01P_REG_RX_PW_P1,      0x00);
+    setRegister(_NRF24L01P_REG_RX_PW_P2,      0x00);
+    setRegister(_NRF24L01P_REG_RX_PW_P3,      0x00);
+    setRegister(_NRF24L01P_REG_RX_PW_P4,      0x00);
+    setRegister(_NRF24L01P_REG_RX_PW_P5,      0x00);
+    setRegister(_NRF24L01P_REG_FIFO_STATUS,   0x00);
+    setRegister(_NRF24L01P_REG_DYNPD,         0x00);
+    setRegister(_NRF24L01P_REG_FEATURE,       0x00);     
+/*********************/
+    wait_us(_NRF24L01P_TIMING_Tundef2pd_us);    // Wait for Power-on reset
+
     setRegister(_NRF24L01P_REG_CONFIG, 0); // Power Down
-    wait_us(_NRF24L01P_TIMING_Tundef2pd_us);
+
     setRegister(_NRF24L01P_REG_STATUS, _NRF24L01P_STATUS_MAX_RT|_NRF24L01P_STATUS_TX_DS|_NRF24L01P_STATUS_RX_DR);   // Clear any pending interrupts
 
     //
@@ -198,7 +223,7 @@
     disableAllRxPipes();
     setRfFrequency();
     setRfOutputPower();
-    setAirDataRate(NRF24L01P_DATARATE_250_KBPS);
+    setAirDataRate();
     setCrcWidth();
     setTxAddress();
     setRxAddress();
@@ -210,6 +235,22 @@
 
 }
 
+void
+nRF24L01P::flush_tx_fifo()
+{
+    nCS_ = 0;
+    int status = spi_.write(_NRF24L01P_SPI_CMD_FLUSH_TX);
+    nCS_ = 1;
+       wait_us( _NRF24L01P_TIMING_Tpece2csn_us );
+}
+void
+nRF24L01P::flush_rx_fifo()
+{
+    nCS_ = 0;
+    int status = spi_.write(_NRF24L01P_SPI_CMD_FLUSH_RX);
+    nCS_ = 1;
+       wait_us( _NRF24L01P_TIMING_Tpece2csn_us );
+}
 
 void nRF24L01P::powerUp(void) {
 
diff -r 7606e50461e1 -r d3349b4b6496 nRF24L01P.h
--- a/nRF24L01P.h	Sat Nov 28 07:13:12 2020 +0000
+++ b/nRF24L01P.h	Sat Nov 28 13:58:50 2020 +0000
@@ -97,6 +97,8 @@
      */
     nRF24L01P(PinName mosi, PinName miso, PinName sck, PinName csn, PinName ce, PinName irq = NC);
 
+    void flush_rx_fifo();
+    void flush_tx_fifo();
     /**
      * Set the RF frequency.
      *