ESP32 io14上升沿中断误触发问题

pengjs
Posts: 18
Joined: Fri Apr 09, 2021 6:32 am

ESP32 io14上升沿中断误触发问题

Postby pengjs » Sat Apr 24, 2021 12:16 pm

tatic void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}

static void gpio_task_example(void* arg)
{
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
}
}
}

void encode_init(void)
{
gpio_config_t io_conf;
//interrupt of rising edge
io_conf.intr_type = GPIO_INTR_POSEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 0;
io_conf.pull_down_en = 1;
gpio_config(&io_conf);

gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);

//hook isr handler for specific gpio pin
//gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_INPUT_IO_1, gpio_isr_handler, (void*) GPIO_INPUT_IO_1);

gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));

xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
}

代码如上,打印信息如下:

[20:06:12.760]收←◆GPIO[14] intr, val: 1
GPIO[14] intr, val: 0

[20:06:12.916]收←◆GPIO[14] intr, val: 1

[20:06:12.946]收←◆GPIO[14] intr, val: 0

[20:06:13.154]收←◆GPIO[14] intr, val: 1

[20:06:13.190]收←◆GPIO[14] intr, val: 0

[20:06:14.735]收←◆GPIO[14] intr, val: 1

[20:06:14.770]收←◆GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0

[20:06:14.812]收←◆GPIO[14] intr, val: 1
GPIO[14] intr, val: 0

[20:06:14.862]收←◆GPIO[14] intr, val: 1

[20:06:14.883]收←◆GPIO[14] intr, val: 0
GPIO[14] intr, val: 1
GPIO[14] intr, val: 1
GPIO[14] intr, val: 0

[20:06:15.665]收←◆GPIO[14] intr, val: 1

[20:06:15.728]收←◆GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0
GPIO[14] intr, val: 0

[20:06:24.936]收←◆GPIO[14] intr, val: 1
GPIO[14] intr, val: 1
GPIO[14] intr, val: 1
GPIO[14] intr, val: 1
GPIO[14] intr, val: 1

提问:[20:06:24.936] [20:06:24.936] 此时打印的logo是否有误,为什么上升沿触发会一直打印0或者1?
按照我的理解,此时应该无法触发上升沿中断。我的理解有误吗?我需要怎么设置代码,才能正确呢?
恳请及时解答,谢谢!

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP32 io14上升沿中断误触发问题

Postby ESP_Gargamel » Sun Apr 25, 2021 1:22 am

GPIO14 的输入是如何接入的?是否有毛刺?如果是基于 generic_gpio 这个 demo 改的话,使用 ESP32 其他 IO 作为输出,是否也有此问题?

pengjs
Posts: 18
Joined: Fri Apr 09, 2021 6:32 am

Re: ESP32 io14上升沿中断误触发问题

Postby pengjs » Sun Apr 25, 2021 6:34 am

问题初步得到了解决,是io接入有毛刺导致的,我继续测试一下看是否完全OK

Who is online

Users browsing this forum: No registered users and 79 guests