Problem with interrupt
The IO Pi Plus is a 32 channel MCP23017 GPIO expander for the Raspberry Pi
22/04/2021
Posted by:
warg
void iopiinterrupt(){
printf("interrupt called \n");
}
int main(int argc, char **argv)
{
int pi = pigpio_start("localhost", "8888");
set_mode(pi, 4, PI_INPUT);
set_pull_up_down(pi, 4, PI_PUD_DOWN);
callback(pi,4, RISING_EDGE, iopiinterrupt);
IOPi_init(0x21, 1); // initialise one of the io pi buses on i2c address 0x20
set_port_pullups( 0x21, 0, 0x00); //turn off the internal 100K pull-up resistors for the selected IO port
set_port_direction(0x21, 0, 0xFF); // set the direction for bank 0 to be inputs
invert_port(0x21, 0, 0x00); //set the polarity of the pins on the port to be normal
set_interrupt_polarity(0x21, 1); // Set the polarity of the interrupt pin to go high.
mirror_interrupts( 0x21, 1); // Set the interrupt pins to be mirrored or for separate ports
set_interrupt_defaults( 0x21, 0, 0x00); // Set the default value to be off for all pins
set_interrupt_type( 0x21, 0, 0xFF); // Sets the type of interrupt to trigger when the pin matches the default value
set_interrupt_on_port( 0x21, 0, 0xFF); // Enable interrupts for all pins on port 0
reset_interrupts( 0x21);
while (1){}
return 0;
}
22/04/2021
Posted by:
andrew
One problem I can see with your code is the iopiinterrupt() function does not reset the IO Pi interrupts when it is triggered so the IA and IB pins will stay high after they have been triggered once. Try changing the function to the following code and see if the interrupts behave properly.
void iopiinterrupt(){
printf("interrupt called \n");
reset_interrupts( 0x21);
}
If you still have problems check that your inputs have pull-down resistors to keep them low. If you have inputs attached, for example, a button, that does not pull down to ground when it is off the input will be left in a floating state which could cause the interrupts to trigger randomly if any interference or capacitance on the cable pulls the voltage high enough for the IO chip to see it as a high input.
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.