Does the Electron support external interrupts?

Hi,

I’m using the Electron, and I’d like to set an interrupt handler for one of the external Dx pins (ex: D0, D1).
Looking at the documentation, it seems to imply that interrupts are supported only on the Core and Photon.

Is this possible with the Electron, can I hook interrupts from INPUT pins?

Thanks

-John

Yup, the docs lag behind a few years here :flushed:

The list of availabe interrupt pins for the Electron is similar to the Photon’s.
To know which pins share EXTI lines with other pins you’d need to look at the GPIO numbers in the pin overview in the datasheets where Px## stands for Port x bit ## and all bits with the same number share the same EXTI line across all ports.
So out of Ports A, B, C & D only one ## can have an independent interrupt assigned.
e.g. for the Photon you read D0 and A5 can’t be used since they share the EXTI line with SETUP - that’s because D0 is PB 7, A5 is PA 7 and SETUP is PC 7 (see https://docs.particle.io/datasheets/photon-datasheet/#pinout-diagrams)

For the Electron the GPIO setup can be found here (unfortunately the extra GPIOs for SETUP & RGB are not documented there as they are for the Photon)

(@KyleG, could you get someone at Particle to update the docs accordingly, please)

1 Like

Thanks for the quick response @ScruffR !

That’s great news. It took me a few minutes to unpack your explanation, but I think I have it now. :slight_smile:

How many unique EXTI lines are there, and how do I reference them in attachInterrupt()?
If I look at the Arduino library, there is a digitalPinToInterrupt() mapping function.

I get the impression that perhaps for Particle, the mapping is done for me in the attachInterrupt()?
So if I code

attachInterrupt(D1, handler, CHANGE);

It maps D1 to #6 (because D1 is PB6)?

-John

I'd have to look into the STM32F2xx datasheet again (or you could here), but some faint memory goes like this (with a pinch of salt tho'):
There are 16 bits (GPIOs) per port and I think to remember bits 0..7 do have one dedicated EXTI line each while bits 8..11 share one and 9..15 also one, so you have 10 independent EXTI lines.
But you won't need to care about the EXTI lines in code, since attachInterrupt() just takes the pin "name" - only if you need several interrupts, you need to make sure that the bit numbers on the port don't collide with the bit numbers of another port already used for an interrupt, otherwise your previous interrupt assignment would just be overruled.

Exactly!

1 Like