Hi DaneLLL,
I am sharing the I’ve followed to help reproduce the issue on the Orin Nano Devkit.
Pin Configuration: I configured the following GPIOs as bidirectional in the Pinmux spreadsheet and generated the corresponding .dtsi file, replacing the generated settings:
GPIO1: PCC.00
GPIO2: PCC.01
GPIO3: PCC.02
GPIO4: PCC.03
Application Implementation: I developed a C command-line application using the libgpiod framework to control these GPIOs, including changing their direction and values. I can successfully modify the values and directions of the GPIOs, but I am unable to retrieve the correct value from the input GPIOs.
Additional Information:
I also tried using the gpioset and gpioget command-line tools, but faced the same issue. Specifically, when I set GPIO PCC.00 to output with a value of 1, I can successfully retrieve the value once using gpioget. However, on subsequent attempts, the value always returns as zero.
Additionally, in the Pinmux configuration, GPIO is correctly set, and it is not configured as SFIO, only as a GPIO.
Please let me know if you need any further details to help resolve this issue.
#include <stdio.h>
#include <unistd.h>
#include <gpiod.h>
#define GPIO2_PIN 12
#define GPIO3_PIN 13
#define GPIOD_LINE_DIRECTION_INPUT 0
#define GPIOD_LINE_DIRECTION_OUTPUT 1
// Function to initialize GPIO lines with error handling
struct gpiod_line *init_gpio(struct gpiod_chip *chip, int pin, int direction) {
struct gpiod_line *line = gpiod_chip_get_line(chip, pin);
if (!line) {
perror("Unable to get GPIO line");
return NULL;
}
// Request the line as input or output
if (direction == GPIOD_LINE_DIRECTION_OUTPUT) {
if (gpiod_line_request_output(line, "gpio_program", 0) < 0) {
perror("Failed to request GPIO line as output");
return NULL;
}
} else if (direction == GPIOD_LINE_DIRECTION_INPUT) {
if (gpiod_line_request_input(line, "gpio_program_input") < 0) {
perror("Failed to request GPIO line as input");
return NULL;
}
}
return line;
}
int main() {
struct gpiod_chip *chip1;
struct gpiod_line *line2, *line3;
int value1, value2;
// Open gpiochip1 for GPIO2 and GPIO3
chip1 = gpiod_chip_open_by_name("gpiochip1");
if (!chip1) {
perror("Unable to open GPIO chip 1");
return 1;
}
// Initialize GPIO2 as input, GPIO3 as output
line2 = init_gpio(chip1, GPIO2_PIN, GPIOD_LINE_DIRECTION_INPUT); // GPIO2 as input
usleep(500000);
line3 = init_gpio(chip1, GPIO3_PIN, GPIOD_LINE_DIRECTION_OUTPUT); // GPIO3 as output
if (line2 && line3) {
value1 = gpiod_line_set_value(line3, 1); // Set GPIO3 to 1 (output)
usleep(500000); // Allow signal to propagate
value1 = gpiod_line_get_value(line3);
value2 = gpiod_line_get_value(line2); // Read GPIO2 (input)
printf("GPIO3 set to %d, GPIO2 value: %d\n", value1, value2);
} else {
printf("Error in setting up GPIO lines\n");
}
// Clean up and release GPIO lines
gpiod_line_release(line2);
gpiod_line_release(line3);
usleep(1000000); // Wait a bit before the next iteration
gpiod_chip_close(chip1);
return 0;
}
Thanks