IO Pi Plus interrupt-driven input
10824 Views - Created 23/11/2015
It seems that I could probably wire the INTA/INTB pins of each bus, through a level shifter, then into one of the standard GPIO pins. Then I could use GPIO.add_event_callback() to set up a button handler for each IO Bus.
[This project is going to require four stacked IO Pi Plus boards, so managing the button presses is going to be no small matter.]
Has anyone done this? Is there a better way to implement a true interrupt driven input with the IO Pi Plus?
As the interrupt pins are 5V you will need a voltage divider to drop the voltage down to 3.3V before connecting it to a GPIO pin. We have a voltage divider calculator you can use to find suitable values but a 10K between the interrupt pin and GPIO and a 19.1K between the GPIO and ground should work.
To reduce the number of GPIO pins needed you can use the mirror_interrupts function to connect both interrupt pins on each bus together so if an interrupt occurs on any of the 16 pins on the bus both interrupt pins will go high. This way only 8 GPIO pins will be needed for 4 IO Pi Plus boards. When an interrupt is triggered on the Raspberry Pi GPIO pin you will know which bus it occurred on so you can use two read_port function calls to poll both ports on the bus and find out which pin was pressed.
I will try and work on a tutorial to explain all of this better over the next couple of days.
After playing around with the code and the Raspberry Pi I found that a level shifter works more reliably than a voltage divider. With the voltage divider, the interrupts would not always reset for some unknown reason. It is also more reliable if the interrupt pins are set to be high by default and then fall low when triggered.
The tutorial uses a function which is triggered in a new thread by a falling edge on the GPIO pin. The function checks the status of the interrupts and returns a list of the pins which are set high.
Hopefully, this should help you with your project.
I assume you used one of the DFC6301 type level shifters? Unfortunately I don't have any of those in-hand.
Did you happen to try a diode/pull-up style converter? I would expect that would give a cleaner level than the voltage divider and might work better, but not sure if "better enough". I'll give that a try since I have the parts on-hand to try it.
Have you tried using our Windows 10 IOT library for the IO Pi? It includes a ResetInterrupts() function in the IO Pi class for resetting the interrupts which should pull both of the interrupt pins low. Although looking at how the ResetInterrupt function works it does appear to be doing the same as you by reading the INTCAP register.
You may also find the interrupt pins are more reliable with a level shifter if you set them to be high by default so they go low when triggered. I am not sure why this is but it does seem to work more reliably this way. Alternatively, adding a 10K resistor to the interrupt pin and ground may help with making sure the pin pulls back low when it is reset.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.