- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/semphr.h"
- #include "driver/gpio.h"
- #define BUTTON_PIN GPIO_NUM_2
- // Semaphore to synchronize tasks
- SemaphoreHandle_t xSemaphore = NULL;
- // Interrupt service routine for the button press
- static void IRAM_ATTR button_isr_handler(void* arg) {
- // Notify the waiting task that the button was pressed
- xSemaphoreGiveFromISR(xSemaphore, NULL);
- }
- // Task that will be notified when the button is pressed
- void button_task(void *arg) {
- while (1) {
- // Wait for the semaphore to be given by the ISR
- if (xSemaphoreTake(xSemaphore, portMAX_DELAY)) {
- esp_wifi_start();
- printf("Button Pressed!\n");
- }
- }
- }
- void vTaskISR(void *pvParameters)
- {
- while(1)
- {
- xSemaphore = xSemaphoreCreateBinary();
- // Configure the GPIO pin for the button
- gpio_config_t io_conf = {
- .pin_bit_mask = (1ULL << BUTTON_PIN),
- .mode = GPIO_MODE_INPUT,
- .intr_type = GPIO_INTR_POSEDGE,
- .pull_up_en = GPIO_PULLUP_ENABLE,
- };
- gpio_config(&io_conf);
- // Install ISR service with default configuration
- gpio_install_isr_service(0);
- // Hook ISR handler to the button pin
- gpio_isr_handler_add(BUTTON_PIN, button_isr_handler, (void*) BUTTON_PIN);
- vTaskDelete(NULL);
- }
- }
- void app_main() {
- xTaskCreate(&vTaskISR, "ISR", 4096, NULL, 5, NULL);
- }
Interrupt Service Routine on esp32
-
- Posts: 4
- Joined: Fri Nov 03, 2023 4:07 pm
Interrupt Service Routine on esp32
Hello guys I'm working on a project that activate wifi interface when a button is pressed so I created a project that print a message when the event is triggered the code works fine but when I integrated the same code in the main project the interruption doesn't work
-
- Posts: 1705
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Interrupt Service Routine on esp32
Code: Select all
// Task that will be notified when the button is pressed
void button_task(void *arg) {
...
Who is online
Users browsing this forum: No registered users and 103 guests