- 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口中断功能?谢谢
关于ESP32 IO口配置成中断的问题
关于ESP32 IO口配置成中断的问题
Re: 关于ESP32 IO口配置成中断的问题
我想用不同的方式实现IO的中断功能。你知道我哪里错了吗?
-
- Posts: 118
- Joined: Tue Jun 26, 2018 3:09 am
Re: 关于ESP32 IO口配置成中断的问题
麻烦你把问题再描述下, 提供下你的需求,以及目前的状态:
1. 哪一个IO无法产生中断?
2. 两个case的作用分别是什么?
3. 你是如何判断中断配置没有生效的?
4. example 能满足你的需求嘛?
1. 哪一个IO无法产生中断?
2. 两个case的作用分别是什么?
3. 你是如何判断中断配置没有生效的?
4. example 能满足你的需求嘛?
Who is online
Users browsing this forum: No registered users and 58 guests