Timer interrupt TASK in ESP32 IDF using interrupts

I'm a beginner learning ESP32 using IDF and having a task to use interrupt timer. The task is to generate a signal using GPIO pin. The signal should be on for 20ms and off for 6ms. Here is the code that I've tried. I don't know where I'm going wrong and please guide me if my understanding is wrong.

#include <stdio.h>
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include <stdbool.h>
#include "esp_err.h"
#include "sdkconfig.h"
void timer_callback_1(void *param)
{ gpio_set_level(GPIO_NUM_2, 1);
}
void timer_callback_2(void *param)
{ gpio_set_level(GPIO_NUM_2, 0);
}
void app_main(void)
{ gpio_pad_select_gpio(GPIO_NUM_2); gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT); const esp_timer_create_args_t my_timer_args = { .callback = &timer_callback_1, .name = "a timer"}; esp_timer_handle_t timer_handler; ESP_ERROR_CHECK(esp_timer_create(&my_timer_args, &timer_handler)); ESP_ERROR_CHECK(esp_timer_start_periodic(timer_handler, 20000)); ESP_ERROR_CHECK(esp_timer_stop(timer_handler)); const esp_timer_create_args_t my_timer_args_2 = { .callback = &timer_callback_2, .name = "b timer"}; ESP_ERROR_CHECK(esp_timer_create(&my_timer_args_2, &timer_handler)); ESP_ERROR_CHECK(esp_timer_start_periodic(timer_handler, 6000)); ESP_ERROR_CHECK(esp_timer_stop(timer_handler)); //ESP_ERROR_CHECK(esp_timer_start_once(timer_handler, 20000)); while (true) { esp_timer_dump(stdout); vTaskDelay(pdMS_TO_TICKS(1000)); }
}
4 Related questions 22 How can I create a symfony twig filter? 3 Custom filters for Twig in Silex 5 Twig's custom filters aren't working Related questions 22 How can I create a symfony twig filter? 3 Custom filters for Twig in Silex 5 Twig's custom filters aren't working 1 Twig - earlier raw filter 0 How to use custom Twig filters in Twig template rendered from string? 7 twig filter multiple parameters 1 Create a simple twig filter 1 Twig Add Filter 1 how to create filter new in twig template in php 5 Deprecation of twig filters, use Twig_SimpleFilter instead Load 7 more related questions Show fewer related questions Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like