© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
DevHeads IoT Integration ServerDIIS
DevHeads IoT Integration Server•2y ago•
4 replies
Dtynin

Failed to Add GPIO Callback on AVR32UC Microcontroller

Hi everyone, I'm working on setting up an interrupt handler on my AVR32UC microcontroller, but I'm encountering an issue where the interrupt configuration fails.
my setup:
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define GPIO_PIN 15
#define GPIO_PORT "GPIO_0"

void gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
    printk("Interrupt triggered!\n");
}

void main(void) {
    const struct device *dev = device_get_binding(GPIO_PORT);
    gpio_pin_interrupt_configure(dev, GPIO_PIN, GPIO_INT_EDGE_TO_ACTIVE);
    gpio_init_callback(&my_cb, gpio_callback, BIT(GPIO_PIN));
    gpio_add_callback(dev, &my_cb);
}
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define GPIO_PIN 15
#define GPIO_PORT "GPIO_0"

void gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
    printk("Interrupt triggered!\n");
}

void main(void) {
    const struct device *dev = device_get_binding(GPIO_PORT);
    gpio_pin_interrupt_configure(dev, GPIO_PIN, GPIO_INT_EDGE_TO_ACTIVE);
    gpio_init_callback(&my_cb, gpio_callback, BIT(GPIO_PIN));
    gpio_add_callback(dev, &my_cb);
}

The error I'm encountering:
error: Failed to add GPIO callback
error: Failed to add GPIO callback

I've confirmed that interrupt support is enabled in the
prj.conf
prj.conf
file. Does anyone have suggestions on how to fix this?
Solution
hey @Sterling I had fixed the issue, I made sure to define and initialize the
struct gpio_callback my_cb
struct gpio_callback my_cb
before using it in
gpio_init_callback
gpio_init_callback
. I also added some error handling for functions like
device_get_binding
device_get_binding
,
gpio_pin_interrupt_configure
gpio_pin_interrupt_configure
, and
gpio_add_callback
gpio_add_callback
. These adjustments helped to correctly set up the GPIO interrupt, so now the callback function triggers as expected when the GPIO pin detects an edge. thanks buddy
Jump to solution
DevHeads IoT Integration Server banner
DevHeads IoT Integration ServerJoin
The DevHeads IoT Integration Server accelerates technology engineering by helping pro devs learn, share and collaborate.
2,984Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

GPIO Pin Configuration Error for DHT22 on AVR32UC with Zephyr OS
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago
How to Resolve GPIO Pin Configuration Failures for DHT22 Sensor on AVR32UC with Zephyr OS?
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago
utilize a microcontroller's GPIO pins to control peripheral devices in an IoT embedded software in C
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago
Microcontroller Power Optimization Strategies
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
3y ago