Added Flush Tx and Rx Buffer to Owen Edwards version of the library.
Dependents: HexiComm HexiwearAlertSystem Hexi
Fork of nRF24L01P by
Diff: nRF24L01P.cpp
- Revision:
- 1:b3ea38f27b69
- Parent:
- 0:8ae48233b4e4
--- 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; +}