GPIO Pin Configuration Error for DHT22 on AVR32UC with Zephyr OS

@Dark AI Earlier, I added the pinmux settings and ensured they were included in the board's DTS file. The updated configuration looked like this:
&pio {
pinmux_dht22: pinmux_dht22 {
pins = <AVR32_PIN_PB02 GPIO_FUNC>;
};
};

&gpio0 {
status = "okay";
dht22_pin: dht22_pin {
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
};
};
&pio {
pinmux_dht22: pinmux_dht22 {
pins = <AVR32_PIN_PB02 GPIO_FUNC>;
};
};

&gpio0 {
status = "okay";
dht22_pin: dht22_pin {
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
};
};
Despite these changes, I’m still encountering the same error when configuring the GPIO pin.
4 Replies
Dark AI
Dark AI5mo ago
Thanks for the heads-up, @Dtynin . Let’s try a couple more troubleshooting steps. First, ensure that DT_LABEL(DT_NODELABEL(gpio0)) correctly matches the label in your DTS file. To gather more debugging information, modify your code as follows:
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define DHT22_PIN 2
#define GPIO_PORT DT_LABEL(DT_NODELABEL(gpio0))

const struct device *gpio_dev;

void main(void)
{
printk("Starting DHT22 sensor integration\n");

gpio_dev = device_get_binding(GPIO_PORT);
if (!gpio_dev) {
printk("Failed to bind GPIO device: %s\n", GPIO_PORT);
return;
} else {
printk("Successfully bound to GPIO device: %s\n", GPIO_PORT);
}

int ret = gpio_pin_configure(gpio_dev, DHT22_PIN, GPIO_INPUT);
if (ret < 0) {
printk("Failed to configure GPIO pin %d, error: %d\n", DHT22_PIN, ret);
} else {
printk("Successfully configured GPIO pin %d\n", DHT22_PIN);
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define DHT22_PIN 2
#define GPIO_PORT DT_LABEL(DT_NODELABEL(gpio0))

const struct device *gpio_dev;

void main(void)
{
printk("Starting DHT22 sensor integration\n");

gpio_dev = device_get_binding(GPIO_PORT);
if (!gpio_dev) {
printk("Failed to bind GPIO device: %s\n", GPIO_PORT);
return;
} else {
printk("Successfully bound to GPIO device: %s\n", GPIO_PORT);
}

int ret = gpio_pin_configure(gpio_dev, DHT22_PIN, GPIO_INPUT);
if (ret < 0) {
printk("Failed to configure GPIO pin %d, error: %d\n", DHT22_PIN, ret);
} else {
printk("Successfully configured GPIO pin %d\n", DHT22_PIN);
}
}
This will provide more information about where the failure is happening. Additionally, ensure there are no conflicts with other peripherals or pins. Can you run this modified code and share the output logs?
Dtynin
Dtynin5mo ago
This is the output log from the modified code I tried:
Starting DHT22 sensor integration
Successfully bound to GPIO device: gpio0
Failed to configure GPIO pin 2, error: -22
Starting DHT22 sensor integration
Successfully bound to GPIO device: gpio0
Failed to configure GPIO pin 2, error: -22
Dark AI
Dark AI5mo ago
The error code -22 (EINVAL) indicates an invalid argument. Verify your GPIO controller supports the desired configuration, check if GPIO_INPUT is the correct flag, refer to Zephyr OS documentation and examples, and ensure your DTS file has the correct pin and port settings.
Dtynin
Dtynin5mo ago
After checking the GPIO controller capabilities and flags, I realized I needed an additional flag for the input configuration. Here’s the updated code:
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define DHT22_PIN 2
#define GPIO_PORT DT_LABEL(DT_NODELABEL(gpio0))

const struct device *gpio_dev;

void main(void)
{
printk("Starting DHT22 sensor integration\n");

gpio_dev = device_get_binding(GPIO_PORT);
if (!gpio_dev) {
printk("Failed to bind GPIO device: %s\n", GPIO_PORT);
return;
} else {
printk("Successfully bound to GPIO device: %s\n", GPIO_PORT);
}

int ret = gpio_pin_configure(gpio_dev, DHT22_PIN, GPIO_INPUT | GPIO_PULL_UP);
if (ret < 0) {
printk("Failed to configure GPIO pin %d, error: %d\n", DHT22_PIN, ret);
} else {
printk("Successfully configured GPIO pin %d\n", DHT22_PIN);
}
}
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>

#define DHT22_PIN 2
#define GPIO_PORT DT_LABEL(DT_NODELABEL(gpio0))

const struct device *gpio_dev;

void main(void)
{
printk("Starting DHT22 sensor integration\n");

gpio_dev = device_get_binding(GPIO_PORT);
if (!gpio_dev) {
printk("Failed to bind GPIO device: %s\n", GPIO_PORT);
return;
} else {
printk("Successfully bound to GPIO device: %s\n", GPIO_PORT);
}

int ret = gpio_pin_configure(gpio_dev, DHT22_PIN, GPIO_INPUT | GPIO_PULL_UP);
if (ret < 0) {
printk("Failed to configure GPIO pin %d, error: %d\n", DHT22_PIN, ret);
} else {
printk("Successfully configured GPIO pin %d\n", DHT22_PIN);
}
}
Now it’s working perfectly. Thanks for the help! @Dark AI
Want results from more Discord servers?
Add your server