关于ESP32 IO口配置成中断的问题

qq4056
Posts: 3
Joined: Mon Dec 03, 2018 12:17 pm

关于ESP32 IO口配置成中断的问题

Postby qq4056 » Mon Dec 03, 2018 1:20 pm

Code: Untitled.c Select all


void PT_GpioInit()
{
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);

//interrupt of rising edge
io_conf.intr_type = GPIO_PIN_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 = 1;
gpio_config(&io_conf);

//change gpio intrrupt type for one pin
gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_ANYEDGE);

//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);

//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_5, gpio_isr_handler, (void*) GPIO_NUM_5);

//remove isr handler for gpio number.
gpio_isr_handler_remove(GPIO_NUM_4);
//hook isr handler for specific gpio pin again
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
}


void test_PT_GpioInit()
{
printf("test_PT_GpioInit()\n");
gpio_pad_select_gpio(GPIO_NUM_18);
gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT);

gpio_pad_select_gpio(GPIO_NUM_19);
gpio_set_direction(GPIO_NUM_19, GPIO_MODE_OUTPUT);

gpio_intr_disable(GPIO_NUM_18);
gpio_intr_disable(GPIO_NUM_19);

gpio_pulldown_dis(GPIO_NUM_18 );
gpio_pulldown_dis(GPIO_NUM_19);

gpio_pullup_dis(GPIO_NUM_18 );
gpio_pullup_dis(GPIO_NUM_19);


gpio_pad_select_gpio(GPIO_NUM_4);
gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT);

gpio_pad_select_gpio(GPIO_NUM_5);
gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT);

gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_NEGEDGE );
gpio_set_intr_type(GPIO_NUM_5, GPIO_INTR_NEGEDGE );

gpio_pullup_en(GPIO_NUM_4);
gpio_pullup_en(GPIO_NUM_5);

gpio_intr_enable(GPIO_NUM_4);
gpio_intr_enable(GPIO_NUM_5);


//gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_ANYEDGE);
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(100, sizeof(uint32_t));


//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_NUM_5, gpio_isr_handler, (void*) GPIO_NUM_5);

//remove isr handler for gpio number.
gpio_isr_handler_remove(GPIO_NUM_4);
//hook isr handler for specific gpio pin again
gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
}

我的问题是:如何把test_PT_GpioInit()配置成和PT_GpioInit()一样,实现IO口中断功能?谢谢

costaud
Espressif staff
Espressif staff
Posts: 55
Joined: Wed Dec 30, 2015 5:09 pm

Re: 关于ESP32 IO口配置成中断的问题

Postby costaud » Thu Dec 06, 2018 4:13 am

为什么不直接用第一个函数的初始化代码 ?

qq4056
Posts: 3
Joined: Mon Dec 03, 2018 12:17 pm

Re: 关于ESP32 IO口配置成中断的问题

Postby qq4056 » Thu Dec 06, 2018 12:39 pm

我想用不同的方式实现IO的中断功能。你知道我哪里错了吗?

houwenxiang
Espressif staff
Espressif staff
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: 关于ESP32 IO口配置成中断的问题

Postby houwenxiang » Mon Dec 10, 2018 7:05 am

我想用不同的方式实现IO的中断功能。你知道我哪里错了吗?
第二段代码的现象是什么?不能产生中断吗? 触发源是什么? 如果是 18 和 19 的话试着使能一下 18, 19 的上拉模式.
wookooho

qq4056
Posts: 3
Joined: Mon Dec 03, 2018 12:17 pm

Re: 关于ESP32 IO口配置成中断的问题

Postby qq4056 » Wed Dec 12, 2018 1:43 pm

没有产生中断,不知道什么原因 :shock:

Xiong Yu
Espressif staff
Espressif staff
Posts: 9
Joined: Wed Apr 11, 2018 12:08 am

Re: 关于ESP32 IO口配置成中断的问题

Postby Xiong Yu » Sat Dec 15, 2018 8:45 am

麻烦你把问题再描述下, 提供下你的需求,以及目前的状态:
1. 哪一个IO无法产生中断?
2. 两个case的作用分别是什么?
3. 你是如何判断中断配置没有生效的?
4. example 能满足你的需求嘛?

Who is online

Users browsing this forum: No registered users and 2 guests