LOCAL void RF24_startListening(void) { RF24_DEBUG(PSTR("RF24:start listening\n")); // toggle PRX RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(PWR_UP) | _BV(PRIM_RX) ); // all RX pipe addresses must be unique, therefore skip if node ID is 0xFF if(MY_RF24_NODE_ADDRESS!=AUTO) RF24_setPipeLSB(RX_ADDR_P0, MY_RF24_NODE_ADDRESS); // start listening RF24_ce(HIGH); }
LOCAL void RF24_stopListening(void) { RF24_DEBUG(PSTR("RF24:stop listening\n")); RF24_ce(LOW); // timing delayMicroseconds(130); RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(PWR_UP) ); // timing delayMicroseconds(100); }
LOCAL bool RF24_initialize(void) { // Initialize pins pinMode(MY_RF24_CE_PIN,OUTPUT); pinMode(MY_RF24_CS_PIN,OUTPUT); // Initialize SPI _SPI.begin(); RF24_ce(LOW); RF24_csn(HIGH); // CRC and power up RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(PWR_UP) ) ; // settle >2ms delay(5); // set address width RF24_setAddressWidth(MY_RF24_ADDR_WIDTH); // auto retransmit delay 1500us, auto retransmit count 15 RF24_setRetries(RF24_ARD, RF24_ARC); // set channel RF24_setChannel(MY_RF24_CHANNEL); // set data rate and pa level RF24_setRFSetup(MY_RF24_RF_SETUP); // sanity check #if defined(MY_RF24_SANITY_CHECK) if (!RF24_sanityCheck()) { RF24_DEBUG(PSTR("RF24:Sanity check failed: configuration mismatch! Check wiring, replace module or non-P version\n")); return false; } #endif // toggle features (necessary on some clones) RF24_enableFeatures(); // enable ACK payload and dynamic payload RF24_setFeature(MY_RF24_FEATURE); // enable broadcasting pipe RF24_setPipe(_BV(ERX_P0 + BROADCAST_PIPE)); // disable AA on all pipes, activate when node pipe set RF24_setAutoACK(0x00); // enable dynamic payloads on used pipes RF24_setDynamicPayload(_BV(DPL_P0 + BROADCAST_PIPE) | _BV(DPL_P0)); // listen to broadcast pipe MY_RF24_BASE_ADDR[0] = BROADCAST_ADDRESS; RF24_setPipeAddress(RX_ADDR_P0 + BROADCAST_PIPE, (uint8_t*)&MY_RF24_BASE_ADDR, BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH); // pipe 0, set full address, later only LSB is updated RF24_setPipeAddress(RX_ADDR_P0, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH); RF24_setPipeAddress(TX_ADDR, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH); // reset FIFO RF24_flushRX(); RF24_flushTX(); // reset interrupts RF24_setStatus(_BV(TX_DS) | _BV(MAX_RT) | _BV(RX_DR)); return true; }
LOCAL void RF24_powerDown(void) { RF24_ce(LOW); RF24_setRFConfiguration(MY_RF24_CONFIGURATION); RF24_DEBUG(PSTR("RF24:PD\n")); // power down }