I'm on day 1 of my ESP32 programming, and could use some guidance on a simple test-app I want to make for my "Sparkfun ESP32 Thing".
I got Blinky example working, and now I want to rewrite my application so that the LED is triggered from one of the buttons instead.
Below is what I've got so far. As far as I can tell the button and LED should be configured, but I'm uncertain if the interrupt code is correct.
I use "make app-flash" to upload the code, and then "make monitor" to see whats going on. It gives me this output;
Also, when I press the button nothing happens.Button configured
LED configured
Interrupt configured
Task watchdog got triggered. The following tasks did not feed the watchdog in time:
- IDLE (CPU 0)
Tasks currently running:
CPU 0: buttonToLED
CPU 1: IDLE
Task watchdog got triggered. The following tasks did not feed the watchdog in time:
- IDLE (CPU 0)
Tasks currently running:
CPU 0: buttonToLED
CPU 1: IDLE
Would you mind commenting on what I'm doing wrong?
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/gpio.h"
#include <esp_log.h>
#define LED_GPIO GPIO_SEL_5
#define BUTTON_GPIO GPIO_SEL_0
void button_pressed_handler(void *args)
{
printf("Button pressed");
int btn_state = gpio_get_level(BUTTON_GPIO);
gpio_set_level(LED_GPIO,btn_state);
}
void setup_button_to_led(void *pvParameter)
{
//Configure button
gpio_config_t btn_config;
btn_config.intr_type = GPIO_INTR_POSEDGE; //Enable interrupt on positive edge
btn_config.mode = GPIO_MODE_INPUT; //Input
btn_config.pin_bit_mask = BUTTON_GPIO; //Set pin where button is connected
btn_config.pull_up_en = GPIO_PULLUP_DISABLE; //Disable pullup
btn_config.pull_down_en = GPIO_PULLDOWN_ENABLE; //Enable pulldown
gpio_config(&btn_config);
printf("Button configured\n");
//Configure LED
gpio_pad_select_gpio(LED_GPIO);
gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
printf("LED configured\n");
//Configure interrupt and add handler
gpio_install_isr_service(0);
gpio_isr_handler_add(BUTTON_GPIO, button_pressed_handler, NULL);
printf("Interrupt configured\n");
//Wait for button press
while (1)
{
ESP_LOGD("test", "Waiting for button press....");
}
}
void app_main()
{
xTaskCreate(&setup_button_to_led, "buttonToLED", 4096, NULL, 5, NULL);
}