NRFs are now read after they raised an interrupt and are not pulled anymore
This commit is contained in:
parent
cc521dcd43
commit
c58298f1da
@ -30,16 +30,28 @@ RF24 NRF_1(NRF_1_CE, NRF_1_CS);
|
||||
RF24 NRF_2(NRF_2_CE, NRF_2_CS);
|
||||
PCF8574 PCF(0x20);
|
||||
|
||||
const uint8_t ADDR[] = "WEST1";
|
||||
const uint8_t ADDR[] = "WEST1", ADDR2[] = "ABCDE";
|
||||
uint64_t timeStamp(0), recvSlot(0), packetTimeout(0);
|
||||
uint32_t freeMem(0);
|
||||
uint16_t biggestContigMemBlock(0);
|
||||
uint8_t frag(0);
|
||||
volatile boolean IRQFlag(false);
|
||||
|
||||
IRAM_ATTR void NRFIRQsHandler(void *p)
|
||||
{
|
||||
Serial.println("NRF IRQs detected !");
|
||||
*(boolean *)p = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
//We do not need to read on the serial bus
|
||||
delay(1000);
|
||||
Serial.println("\nSetup begin");
|
||||
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
|
||||
Serial.println("Setup begin");
|
||||
//We set the RXD0 as a GPIO
|
||||
pinMode(D9, FUNCTION_3);
|
||||
pinMode(D9, INPUT);
|
||||
attachInterruptArg(D9,&(NRFIRQsHandler), (void *)&IRQFlag, FALLING);
|
||||
//To prevent wear and tear on the flash mem
|
||||
WiFi.persistent(false);
|
||||
WiFi.disconnect(true);
|
||||
@ -82,22 +94,69 @@ void setup() {
|
||||
Serial.println("End setup");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
void loop()
|
||||
{
|
||||
if(millis() - recvSlot > RECV_CHECK)
|
||||
{
|
||||
if(NRF_1.available()) //Then we read the incoming data
|
||||
//We check if we got and IRQ from one, both NRFs
|
||||
if(IRQFlag)
|
||||
{
|
||||
bool tx_ok, tx_fail, rx_ready;
|
||||
//We read the PCFs IO to check which NRF raised the IRQ :
|
||||
if(!PCF.digitalRead(PCF8574::P1)) //IRQs are active low
|
||||
{
|
||||
Serial.printf("NRF 1 triggered the IRQs\n Checking why :\n");
|
||||
NRF_1.whatHappened(tx_ok, tx_fail, rx_ready);
|
||||
if(tx_ok)
|
||||
{
|
||||
Serial.println("NRF 1 TX_OK");
|
||||
}
|
||||
if(tx_fail)
|
||||
{
|
||||
Serial.println("NRF 1 TX_FAIL");
|
||||
}
|
||||
if(rx_ready)
|
||||
{
|
||||
Serial.printf("NRF 1 Received %u bytes with sig(%s) : \n",NRF_1.getPayloadSize(), NRF_1.testRPD()?"good":"bad");
|
||||
NRF_1.read(&p, sizeof(p));
|
||||
Serial.printf("NRF 1 Received : \n");
|
||||
debugStruct(&p);
|
||||
}
|
||||
if(NRF_2.available()) //Then we read the incoming data
|
||||
}
|
||||
if(!PCF.digitalRead(PCF8574::P0)) //IRQs are active low
|
||||
{
|
||||
Serial.printf("NRF 2 triggered the IRQs\n Checking why :\n");
|
||||
NRF_2.whatHappened(tx_ok, tx_fail, rx_ready);
|
||||
if(tx_ok)
|
||||
{
|
||||
Serial.println("NRF 2 TX_OK");
|
||||
}
|
||||
if(tx_fail)
|
||||
{
|
||||
Serial.println("NRF 2 TX_FAIL");
|
||||
}
|
||||
if(rx_ready)
|
||||
{
|
||||
Serial.printf("NRF 2 Received %u bytes with sig(%s) : \n",NRF_2.getPayloadSize(), NRF_2.testRPD()?"good":"bad");
|
||||
NRF_2.read(&p, sizeof(p));
|
||||
Serial.printf("NRF 2 Received : \n");
|
||||
debugStruct(&p);
|
||||
}
|
||||
}
|
||||
|
||||
//We check if the RX fifo the NRFs are full
|
||||
//If yes, it means we have a big problem since packets can be thrown away without notice
|
||||
//Could be due to missed IRQs (very bad)
|
||||
if(NRF_1.rxFifoFull())
|
||||
{
|
||||
Serial.println("NRF 1 FIFO FULL !!!!!!!!!!!!");
|
||||
NRF_1.flush_rx();
|
||||
}
|
||||
if(NRF_2.rxFifoFull())
|
||||
{
|
||||
Serial.println("NRF 2 FIFO FULL !!!!!!!!!!!!");
|
||||
NRF_2.flush_rx();
|
||||
}
|
||||
IRQFlag = false;
|
||||
}
|
||||
recvSlot = millis();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user