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

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

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

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

  1. void PT_GpioInit()
  2. {
  3.     gpio_config_t io_conf;
  4.     //disable interrupt
  5.     io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
  6.     //set as output mode
  7.     io_conf.mode = GPIO_MODE_OUTPUT;
  8.     //bit mask of the pins that you want to set,e.g.GPIO18/19
  9.     io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
  10.     //disable pull-down mode
  11.     io_conf.pull_down_en = 0;
  12.     //disable pull-up mode
  13.     io_conf.pull_up_en = 0;
  14.     //configure GPIO with the given settings
  15.     gpio_config(&io_conf);
  16.  
  17.     //interrupt of rising edge
  18.     io_conf.intr_type = GPIO_PIN_INTR_POSEDGE;
  19.     //bit mask of the pins, use GPIO4/5 here
  20.     io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
  21.     //set as input mode
  22.     io_conf.mode = GPIO_MODE_INPUT;
  23.     //enable pull-up mode
  24.     io_conf.pull_up_en = 1;
  25.     gpio_config(&io_conf);
  26.  
  27.     //change gpio intrrupt type for one pin
  28.     gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_ANYEDGE);
  29.  
  30.     //create a queue to handle gpio event from isr
  31.     gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
  32.     //start gpio task
  33.     xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
  34.  
  35.     //install gpio isr service
  36.     gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  37.     //hook isr handler for specific gpio pin
  38.     gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
  39.     //hook isr handler for specific gpio pin
  40.     gpio_isr_handler_add(GPIO_NUM_5, gpio_isr_handler, (void*) GPIO_NUM_5);
  41.  
  42.     //remove isr handler for gpio number.
  43.     gpio_isr_handler_remove(GPIO_NUM_4);
  44.     //hook isr handler for specific gpio pin again
  45.     gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
  46. }
  47.  
  48.  
  49. void test_PT_GpioInit()
  50. {
  51.     printf("test_PT_GpioInit()\n");
  52.     gpio_pad_select_gpio(GPIO_NUM_18);
  53.     gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT);
  54.  
  55.     gpio_pad_select_gpio(GPIO_NUM_19);
  56.     gpio_set_direction(GPIO_NUM_19, GPIO_MODE_OUTPUT);
  57.  
  58.     gpio_intr_disable(GPIO_NUM_18);
  59.     gpio_intr_disable(GPIO_NUM_19);
  60.  
  61.     gpio_pulldown_dis(GPIO_NUM_18 );
  62.     gpio_pulldown_dis(GPIO_NUM_19);
  63.  
  64.     gpio_pullup_dis(GPIO_NUM_18 );
  65.     gpio_pullup_dis(GPIO_NUM_19);
  66.  
  67.  
  68.     gpio_pad_select_gpio(GPIO_NUM_4);
  69.     gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT);
  70.  
  71.     gpio_pad_select_gpio(GPIO_NUM_5);
  72.     gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT);
  73.  
  74.     gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_NEGEDGE  );
  75.     gpio_set_intr_type(GPIO_NUM_5, GPIO_INTR_NEGEDGE  );
  76.  
  77.     gpio_pullup_en(GPIO_NUM_4);
  78.     gpio_pullup_en(GPIO_NUM_5);
  79.  
  80.     gpio_intr_enable(GPIO_NUM_4);
  81.     gpio_intr_enable(GPIO_NUM_5);
  82.  
  83.  
  84.     //gpio_set_intr_type(GPIO_NUM_4, GPIO_INTR_ANYEDGE);
  85.     //create a queue to handle gpio event from isr
  86.     gpio_evt_queue = xQueueCreate(100, sizeof(uint32_t));
  87.  
  88.  
  89.     //start gpio task
  90.     xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
  91.     //install gpio isr service
  92.     gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
  93.     //hook isr handler for specific gpio pin
  94.     gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
  95.     //hook isr handler for specific gpio pin
  96.     gpio_isr_handler_add(GPIO_NUM_5, gpio_isr_handler, (void*) GPIO_NUM_5);
  97.  
  98.     //remove isr handler for gpio number.
  99.     gpio_isr_handler_remove(GPIO_NUM_4);
  100.     //hook isr handler for specific gpio pin again
  101.     gpio_isr_handler_add(GPIO_NUM_4, gpio_isr_handler, (void*) GPIO_NUM_4);
  102. }
  103.  
  104. 我的问题是:如何把test_PT_GpioInit()配置成和PT_GpioInit()一样,实现IO口中断功能?谢谢

costaud
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的中断功能。你知道我哪里错了吗?

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

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

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

qq4056 wrote:
Thu Dec 06, 2018 12:39 pm
我想用不同的方式实现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
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 47 guests