Add this to the main loop or a setup function:
ioport_set_pin_dir(EXAMPLE_BUTTON_INT, IOPORT_DIR_INPUT);
ioport_set_pin_mode(EXAMPLE_BUTTON_INT, IOPORT_MODE_PULLUP |
IOPORT_MODE_GLITCH_FILTER);
ioport_set_pin_sense_mode(EXAMPLE_BUTTON_INT, IOPORT_SENSE_FALLING);
if
(!gpio_set_pin_callback(EXAMPLE_BUTTON_INT, pb0_callback, 1)) {
printf(
"Set pin callback failure!\r\n"
);
while
(1) {
}
}
gpio_enable_pin_interrupt(EXAMPLE_BUTTON_INT);
- 1.
Initialize a pin to trigger an interrupt. Here, we initialize PC03 as an input pin with pull up and glitch filter and to generate an interrupt on a falling edge.
ioport_set_pin_dir(EXAMPLE_BUTTON_INT, IOPORT_DIR_INPUT);
ioport_set_pin_mode(EXAMPLE_BUTTON_INT, IOPORT_MODE_PULLUP |
IOPORT_MODE_GLITCH_FILTER);
ioport_set_pin_sense_mode(EXAMPLE_BUTTON_INT, IOPORT_SENSE_FALLING);
- 2.
Set a callback for the pin interrupt.
if
(!gpio_set_pin_callback(EXAMPLE_BUTTON_INT, pb0_callback, 1)) {
printf(
"Set pin callback failure!\r\n"
);
while
(1) {
}
}
- 3.
Enable pin interrupt.
gpio_enable_pin_interrupt(EXAMPLE_BUTTON_INT);