(have reading involves the source code, but failed to find the reason for the error)
The following post initialization code (error in the line 67 program) :
12//# define GPIO_INPUT_IO_0 photo switch
4//# define GPIO_INPUT_IO_1 target signal first, below by analogy to the fifth
# define GPIO_INPUT_IO_2 2
# define GPIO_INPUT_IO_3 14
# define GPIO_INPUT_IO_4 15
# define GPIO_INPUT_IO_5 13
# define GPIO_INPUT_PIN_SEL1 (1 ull & lt;# define GPIO_INPUT_PIN_SEL2 ((1 ull & lt; # define ESP_INTR_FLAG_DEFAULT 0
The static xQueueHandle gpio_evt_queue=NULL;
The static void IRAM_ATTR gpio_isr_handler (void * arg)
{
Uint32_t gpio_num=(arg uint32_t);
XQueueSendFromISR (gpio_evt_queue, & amp; Gpio_num, NULL);
}
//gpio_task is interrupt function callback function, responsible for completing tasks during a break
The static void gpio_task (void * arg)
{
Uint32_t io_num;
While (1) {//continuously read message queue to interruption of treatment at the first time,
If (xQueueReceive (gpio_evt_queue, & amp; Io_num portMAX_DELAY)) {
Printf (" GPIO [% d] intr, val: % d \ n ", io_num, gpio_get_level (io_num));
}
}
}
The static void my_gpio_init ()
{
Gpio_config_t io_conf;
Falling edge//the interrupt
Io_conf. Intr_type=GPIO_PIN_INTR_NEGEDGE;
//bit mask of the pins, use GPIO12 here
Io_conf. Pin_bit_mask=GPIO_INPUT_PIN_SEL1;
//set as input mode
Io_conf. Mode=GPIO_MODE_INPUT;
//enable the pull - up mode
Io_conf. Pull_up_en=1;
Gpio_config (& amp; Io_conf);
//disable interrupt
Io_conf. Intr_type=GPIO_PIN_INTR_DISABLE;
//bit mask of the pins, use GPIO2 4/13/14/15 here
Io_conf. Pin_bit_mask=GPIO_INPUT_PIN_SEL2;
//set as input mode
Io_conf. Mode=GPIO_MODE_INPUT;
//disable the pull - up mode
Io_conf. Pull_up_en=0;
//disable the pull - down mode
Io_conf. Pull_down_en=0;
Gpio_config (& amp; Io_conf);
//create a queue to handle gpio event from isr
Gpio_evt_queue=xQueueCreate (10, sizeof (uint32_t));
//the new queue
XTaskCreate (gpio_task/task/function
,//the task name "gpio_task"
, 2048//task stack size
, NULL//is passed to the function parameter
10//task priority
, NULL);//handle task
//install GPIO interrupt service
ESP_LOGI (TAG, "GPIO interrupt service installation... ");
Gpio_install_isr_service (ESP_INTR_FLAG_DEFAULT);
ESP_LOGI (TAG, "GPIO interrupt service installed");
//register GPIO12 for interrupt service
ESP_LOGI (TAG, "GPIO12 interrupt service registration... ");
//to this problem every time
Gpio_isr_handler_add (GPIO_INPUT_IO_0 gpio_isr_handler, (void *) GPIO_INPUT_IO_0);
ESP_LOGI (TAG, "GPIO12 interrupt service registration complete");
}
below is the related routines:
/* GPIO Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
The software is distributed on an "AS is" BASIS, WITHOUT WARRANTIES OR
The CONDITIONS OF ANY KIND, either express or implied.
*/
#include
#include
#include
# include "freertos/freertos. H"
# include "freertos/task. H"
# include "freertos/queue. H"
# include "driver/gpio. H"
/* *
* Brief:
* This test code shows how to configure gpio and how to use gpio interrupt.
*
* GPIO status:
* GPIO18: output
* GPIO19: output
* GPIO4: input, pulled up, interrupt the from rising edge and falling edge
* GPIO5: input, pulled up, interrupt the from rising edge.
*
* Test:
* Connect GPIO18 with GPIO4
* Connect GPIO19 with GPIO5
* Generate pulses on GPIO18/19, that triggers interrupt on GPIO4/5
*
*/
# define GPIO_OUTPUT_IO_0 18
# define GPIO_OUTPUT_IO_1 19
# define GPIO_OUTPUT_PIN_SEL ((1 ull & lt;# define GPIO_INPUT_IO_0 4
# define GPIO_INPUT_IO_1 5
# define GPIO_INPUT_PIN_SEL ((1 ull & lt;# define ESP_INTR_FLAG_DEFAULT 0
The static xQueueHandle gpio_evt_queue=NULL;
The static void IRAM_ATTR gpio_isr_handler (void * arg)
{
Uint32_t gpio_num=(arg uint32_t);
XQueueSendFromISR (gpio_evt_queue, & amp; Gpio_num, NULL);
}
The static void gpio_task_example (void * arg)
{
Uint32_t io_num;
For (;; ) {
If (xQueueReceive (gpio_evt_queue, & amp; Io_num portMAX_DELAY)) {
Printf (" GPIO [% d] intr, val: % d \ n ", io_num, gpio_get_level (io_num));
}
}
}
Void app_main ()
{
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.G PIO18/19
Io_conf. Pin_bit_mask=GPIO_OUTPUT_PIN_SEL;
//disable the pull - down mode
Io_conf. Pull_down_en=0;
//disable the pull - up mode
Io_conf. Pull_up_en=0;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull