Page 1 of 1
[nRF52] Any examples on interrupt handling for the nRF52?
Posted: Mon Nov 05, 2018 10:58 pm
I did read the generic documentation on interrupt handling (https://docs.micropython.org/en/latest/ ... rules.html
), but I'm having trouble imagining how that works with the nRF52. One or more demo code examples would be helpful.
I've made some further improvements to my OTA code, but to get it to go faster it likely needs to be interrupt driven so that more of the work can be pipelined.
Re: [nRF52] Any examples on interrupt handling for the nRF52?
Posted: Sun Feb 24, 2019 12:00 am
I have worked though the "pin" module, which supports, among other things, irq().
I have attached a simple demo program which illustrates how to catch interrupt events generated from GPIO pins.
This demo captures interrupts from the four switches on the PCA10040 board.
I have only tested this with the Nordic PCA10040 board, but I believe the general method should be applicable to the other Nordic boards as will as custom boards.
I don't see how to attach a file to this post, so I have copied the text below
# This switch-to-pin mapping is for the PCA10040. Change as needed
SWITCH_1_PIN = 13
SWITCH_2_PIN = 14
SWITCH_3_PIN = 15
SWITCH_4_PIN = 16
# Switch callback function
pin = pin_obj.pin()
state = pin_obj.value()
print("event: ", switch_name(pin), " ", switch_state(state))
# Hook interrupts for each switch and set event callback
# Sleep 15 seconds to allow user to press/release switches