输入IO口的信号稳定发生,但是输入IO口的中断并没有稳定触发,会出现部分中断未触发的情况,导致输出IO口不能稳定的输出波形。请问我应该这么做才能让每一个输入信号都被检测到呢?
代码如下:
```c
Code: Select all
volatile u32_t zero_bit=0;
void IRAM_ATTR testgpio_isr_handler(void* arg)
{
zero_bit=0;
}
void IRAM_ATTR gpio_isr_handler_zerow(void* arg)
{
int changebrg=50;
if(zero_bit>105)
gpio_set_level(LIGHT_GPIO, 0);//把这个GPIO输出低电平
else if(zero_bit>=50)
gpio_set_level(LIGHT_GPIO, 1);//把这个GPIO输出高电平
else
gpio_set_level(LIGHT_GPIO, 0);//把这个GPIO输出低电平
zero_bit++;
}
static int gpio_input_init(void)
{
//GPIO口结构体定义
gpio_config_t io_conf;
//边沿触发
io_conf.intr_type =GPIO_PIN_INTR_ANYEDGE;
//选择为输入模式
io_conf.mode = GPIO_MODE_INPUT;
//配置GPIO_OUT寄存器
io_conf.pin_bit_mask = (1<<23);//输入io口23
//设置下拉
io_conf.pull_down_en = 0;
//设置上拉
io_conf.pull_up_en = 1;
//最后配置使能
gpio_config(&io_conf);
//输出IO口配置
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.intr_type =GPIO_PIN_INTR_DISABLE;
//bit mask of the pins that you want to set,e.g.GPIO5
io_conf.pin_bit_mask = (1<<5); //输出IO口5
//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);
//配置中断
gpio_install_isr_service(0);
gpio_isr_handler_add(GPIO_INPUT_ZERO, testgpio_isr_handler, (void*) GPIO_INPUT_ZERO);
return 0;
}
void app_main()
{
gpio_input_init();
esp_timer_handle_t test_p_handle = 0;
//定义一个周期重复运行的定时器结构体
esp_timer_create_args_t test_periodic_arg = {
.callback = &gpio_isr_handler_zerow, //设置回调函数
.arg = NULL, //不携带参数
.name = "gpio_pwm" //定时器名字
};
vTaskDelay(1000/ portTICK_RATE_MS);
ESP_ERROR_CHECK(esp_timer_create(&test_periodic_arg , &test_p_handle));
ESP_ERROR_CHECK(esp_timer_start_periodic(test_p_handle, 80));
}