Use of Interrupt with RadioHead library

Hi all !

I'm using a RFM96W from Adafruit (which is just a breakout board for the SX1276 LoRa® based module)

To handle the communication, the RadioHead library seemed the best choice as it allows you to easily implement encryption, retries and timeouts (as well as setting the interface, etc...) by initializing a driver (corresponding to the chip) and a manager (to implement a reliable datagram)
Link to documentation

Now to my question :
The RFM96W generate a signal on its DIO0 to indicate that a message has arrived, or that a message finished being sent, and I intended to manually write an interrupt handler. However I found in the driver's documentation
" The RH_RF95 driver uses interrupts to react to events in the RFM module, such as the reception of a new packet, or the completion of transmission of a packet. The driver configures the radio so the required interrupt is generated by the radio's DIO0 pin."

Does it means that i shouldn't try to attach my own interrupt handler to this pin, as it's already used by the driver ?

Thank you all, I hope I provided enough info.
If not I'll respond as quickly as I can :slight_smile:

you are not forced to use interrupt. you can using

if(Radio.available())

or

if(Radio.inWaiting())

but if you want, you can write own handler and attach interrupt out pin DIO0 to interrupt input pin of your µC.

Hi Kolaha, thanks for the answer.

The thing is that when initialising the driver, you already give it the interrupt pin number :
RH_RF95 (uint8_t slaveSelectPin=SS, uint8_t interruptPin=2, RHGenericSPI &spi=hardware_spi)

I was wondering if creating my own interrupt handler on the same pin I already gave to the driver was gonna create a conflict.

for sure. but you can set pin to -1 and using own handler for pin 2, is it not so? i am not experienced with RH_RF95.

What problem are you trying to solve by doing this?

I'll give it a try !

Rather than regularly checking if some data is available, and using processing power to do so, I'd rather just have a flag raised when a message has been transmitted and read it then.

By which is meant you have to take over the entirety of the function of the exist interruot whilst somehow shoehorning your own thing into it.

So you'll be reading the library and modifying it I suppose.

a7

So that wouldn't be too hard. Add a callback mechanism to the RadioHead library or exploit one if it already has them.

a7

1 Like

Probably the cleanest method indeed !

I'll try and keep the post updated

Im surely not the only one who would move mountains to avoid interrupts or modifying a library.

Which raises the qusstion: how does this help you at all? If your loop is running smoothly, just use the available calls to check on things at the top of the loop.

If your loop is not running smoothly, that is where you might focus your attention. If you don't know how to write non-blocking code, it would be better to learn now than to keep turning to flags and interrupts and stuff. They are no panacea.

a7

Moreover, the interrupt just indicates (for example) that a new packet has been received by the radio. If you wrote your own ISR for that, you'd have to handle pulling the packet into the processor over SPI, verifying it (destination address, checksum, etc), resetting radio hardware flags as required, etc. If you're going to do all that, why bother with the library at all?

Fair.

Correct. The code is in RH_RF95.cpp and you can modify it, if you like.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.