How to Fix Interrupt-Driven Data Acquisition Issues with MCP9808 on ATmega2560 and Zephyr OS?

hey guys, who knows how I can implement interrupt-driven data acquisition from the MCP9808 sensor using an ATmega2560 and Zephyr OS, and resolve the interrupt not triggering error? I have tried setting up the external interrupt for the MCP9808 sensor and configuring the ISR to read sensor data, but I still encountered the issue of the interrupt not triggering. Here's the code:
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define MCP9808_INT_PIN DT_GPIO_PIN(DT_NODELABEL(gpio0), int_pin)

void sensor_isr(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
LOG_INF("Interrupt triggered");
// Read sensor data here
}

void main(void)
{
const struct device *gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpio0)));
static struct gpio_callback sensor_cb;

gpio_pin_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INPUT | GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&sensor_cb, sensor_isr, BIT(MCP9808_INT_PIN));
gpio_add_callback(gpio_dev, &sensor_cb);
gpio_pin_interrupt_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INT_EDGE_TO_ACTIVE);

while (1) {
k_sleep(K_MSEC(1000));
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(main);

#define MCP9808_INT_PIN DT_GPIO_PIN(DT_NODELABEL(gpio0), int_pin)

void sensor_isr(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
LOG_INF("Interrupt triggered");
// Read sensor data here
}

void main(void)
{
const struct device *gpio_dev = device_get_binding(DT_LABEL(DT_NODELABEL(gpio0)));
static struct gpio_callback sensor_cb;

gpio_pin_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INPUT | GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&sensor_cb, sensor_isr, BIT(MCP9808_INT_PIN));
gpio_add_callback(gpio_dev, &sensor_cb);
gpio_pin_interrupt_configure(gpio_dev, MCP9808_INT_PIN, GPIO_INT_EDGE_TO_ACTIVE);

while (1) {
k_sleep(K_MSEC(1000));
}
}
If the implementation is successful, the output should display a log message indicating that the interrupt has been triggered whenever the MCP9808 sensor generates an interrupt.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server