void RH_RF95::handleInterrupt()
{
// Read the interrupt register
// Serial.println("RH_RF95.cpp: RH_RF95::handleInterrupt");
uint8_t irq_flags = spiRead(RH_RF95_REG_12_IRQ_FLAGS);
Serial.print("i1 "); Serial.println(_mode<<8 | irq_flags, HEX); // DEBUG: output _mode & irq flags
//Serial.print ("irq_flags (reg 0x12) = ");
//Serial.println(irq_flags, HEX);
if (_mode == RHModeRx && irq_flags & (RH_RF95_RX_TIMEOUT | RH_RF95_PAYLOAD_CRC_ERROR))
{
_rxBad++;
}
else if (_mode == RHModeRx && irq_flags & RH_RF95_RX_DONE)
{
// Have received a packet
uint8_t len = spiRead(RH_RF95_REG_13_RX_NB_BYTES);
// Reset the fifo read ptr to the beginning of the packet
spiWrite(RH_RF95_REG_0D_FIFO_ADDR_PTR, spiRead(RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR));
spiBurstRead(RH_RF95_REG_00_FIFO, _buf, len);
_bufLen = len;
//debug
Serial.print("i2 "); Serial.println(_mode<<8 | irq_flags, HEX); // DEBUG: output _mode & irq flags
//debug end
spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags
// debug
uint8_t debug_pim = spiRead(RH_RF95_REG_12_IRQ_FLAGS);
Serial.print("i3 "); Serial.println(_mode<<8 | debug_pim, HEX); // DEBUG: output _mode & irq flags
// debug end
// debug
// Clear IRQ flags again.
spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags
// and read them back
debug_pim = spiRead(RH_RF95_REG_12_IRQ_FLAGS);
Serial.print("i4 "); Serial.println(_mode<<8 | debug_pim, HEX); // DEBUG: output _mode & irq flags
// debug end
// Remember the RSSI of this packet
// this is according to the doc, but is it really correct?
// weakest receiveable signals are reported RSSI at about -66
_lastRssi = spiRead(RH_RF95_REG_1A_PKT_RSSI_VALUE) - 137;
// We have received a message.
validateRxBuf();
if (_rxBufValid)
setModeIdle(); // Got one
}
else if (_mode == RHModeTx && irq_flags & RH_RF95_TX_DONE)
{
_txGood++;
setModeIdle();
}
//debug
Serial.print("i5 "); Serial.println(_mode<<8 | irq_flags, HEX); // DEBUG: output _mode & irq flags
//debug end
spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags
// debug
uint8_t debug_pim = spiRead(RH_RF95_REG_12_IRQ_FLAGS);
Serial.print("i6 "); Serial.println(_mode<<8 | debug_pim, HEX); // DEBUG: output _mode & irq flags
// debug end
// debug
// Clear IRQ flags again.
spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags
// and read them back
debug_pim = spiRead(RH_RF95_REG_12_IRQ_FLAGS);
Serial.print("i7 "); Serial.println(_mode<<8 | debug_pim, HEX); // DEBUG: output _mode & irq flags
// debug end