Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » 8574 and interrupts

Author: markus
15/11/2020 14:21:51
Hi all,

first of all, hello everyone - I'm new here, and I hope I got the right place for my question.
Which is:
I got 4 8574s to read out ~30 buttons (should end up being a game cotroller add-on), and they are connected to 4 PCINT pins on my Pro Micro board. I just found out that IoAbstraction supports an interrupt for the 8574, so what I want to know:
- will IoAbstraction also work with a PCINT interrupt for this case, or do I have to write that part for myself?
- in case it does work, and I only want to use them as inputs, does it make sense to place runLoop (or ioDeviceSync, haven't yet figured out the relationship between these two) in the interrupt handler?

Hope I'm making sense here.

Bye
Markus

Author: davetcc
16/11/2020 08:32:48
Welcome to the forum!

Yes IOAbstraction works with the interrupt pin from the 8574, you wire that pin to an interrupt capable pin on your device, and provide that as the 2nd parameter when creating the expander.

IE: ioFrom8574(address, interruptPin)

You should never call runLoop from a raw interrupt handler. Question, are you using the switches class? If you are using switches to manage your buttons (SwitchInput) then there's nothing to do other than use the interrupt variant of the initialise function.

However, if you are managing all the IO yourself, I recommend that you register the interrupt with TaskManagerIO which IoAbstraction is based on, using its attach interrupt functionality (see the examples). If you do this, then you can do an IO sync with runLoop because you are not in a direct interrupt. Instead you're in a high priority task.

Author: markus
16/11/2020 10:08:52
Thanks - both for the welcone and the response.

However, I'm afraid I didn't make myself clear in my question - let me try again.
I am using an Arduino Pro Micro, which is based on a 32u4, since it handles USB natively, so I can set it up (with the Joystick library) as HID device without additional hardware. The 32u4 has 5 native interrupt pins that each has a dedicated interrupt vector. However, of these 5
- 2 are blocked for RXD and TXD
- 2 are blocked for SCL and SDA
- and the remaining one I've allocated for a rotary encoder (which works fine btw, also using your library - even if switching the accelerationMode was a bit of a hassle smilie )

The 32u4 also has 8 pins capable of PCINT (pin change interrupt) which share one common interrupt vector (PCINT0), four of which I've wired to the interrupt lines from the 8574's. My question is now: would the interrupt version of the switches initialisation also work from the PCINT pins - and if yes, would this also be true for multiple PCINTs (which all will trigger the same interrupt vector)? Simply trying it dry (just compile, don't run - I don't have the time right now, maybe later) is inconclusive, as even
switches.initialiseInterrupt(ioFrom8574(0x20, 99), true);

doesn't trigger a compile error smilie (just out of interest: which interrupt vector would that use - from checking the code, I'd guess it'll end up at 0xff)

Reading a bit deeper into interrupts on Arduino (and your source code), the answer is probably "No", as the Arduino IDE itself won't handle the PCINT pins. So it looks like I'll have to drop the IoAbstraction for my project (at least the switch handling) and use TaskManager directly.

Author: markus
16/11/2020 12:34:45
Hmmm... I'm getting dirty thoughts here. I'd like to use the IoAbstraction class, as that would do a lot of work for me, but I can't use interrupt pins, and I don't want to poll the 8574's in the task manager loop...

would this work:
- initialize through switches.initializeInterrupt with the interrupt set to 0xFF
That should mean the interrupt never gets triggered (as it doesn't exist), but the 8574s are also never sampled, because they're interrupt driven
Then set up my own interrupt handling for the PCINT interrupts, and in the ISR trigger the TaskManager for checkRunLoopAndRepeat or do my own version of that which then triggers IoAbstraction's runLoop?

Might be worth a try.

Author: davetcc
16/11/2020 16:32:19
 
Then set up my own interrupt handling for the PCINT interrupts, and in the ISR trigger the TaskManager for checkRunLoopAndRepeat


Agreed this may work, if you need raw handlers for another reason, to fake an interrupt to task manager just do this:

taskManager.triggerEvents();
which is safe in an ISR, and in fact exactly what task manager does when it handles an interrupt.




Register / Login  |  Desktop view  |  Jump to top of page