Hello everyone,
I'm using ESP32-S2 WROVER. I'm trying to write code for UART RX interrupt. At the time of receiving the controller reboot automatically, It does not enter into the ISR. I don't know why.
Here is my code ,
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "driver/uart.h"
#include "driver/uart_select.h"
#include "hal/uart_hal.h"
#define TXD_PIN 1
#define RXD_PIN 2
#define BUF_SIZE 1024
#define UART_INTR_CONFIG_FLAG ((UART_INTR_RXFIFO_FULL)\
| (UART_INTR_RXFIFO_TOUT) \
| (UART_INTR_RXFIFO_OVF) \
| (UART_INTR_BRK_DET) \
| (UART_INTR_PARITY_ERR))
void IRAM_ATTR uart_intr_handle(void *arg)
{
printf("in ISR\n");
char data[50];
int read_bytes;
read_bytes = uart_read_bytes(UART_NUM_1, &data, BUF_SIZE, 1000 / portTICK_RATE_MS);
data[read_bytes+1] = '\0';
printf("%d Bytes read\n",read_bytes);
printf("%s\n",data);
uart_write_bytes(UART_NUM_1, (const char*) "RX Done", 7);
uart_clear_intr_status(UART_NUM_1, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
}
void app_main(void)
{
uart_config_t uart_config = {
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
};
uart_driver_install(UART_NUM_1, BUF_SIZE*2, 0, 0, NULL, 0);
uart_param_config(UART_NUM_1, &uart_config);
uart_set_pin(UART_NUM_1, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
esp_err_t esp_err;
uart_intr_config_t uart_intr = {
.intr_enable_mask = UART_INTR_CONFIG_FLAG,
.rxfifo_full_thresh = 5,
.rx_timeout_thresh = 0,
.txfifo_empty_intr_thresh = 0,
};
esp_err = uart_intr_config(UART_NUM_1,&uart_intr);
printf("uart intr config %x\n",esp_err);
uart_isr_free(UART_NUM_1);
esp_err = uart_isr_register(UART_NUM_1,uart_intr_handle,NULL,0,NULL);
printf("isr reg %x\n",esp_err);
uart_enable_rx_intr(UART_NUM_1);
while(1)
{
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
Anyone, please help me. if any example code for UART RX Interrupt share please.
Thank You
UART RX Interrupt
Re: UART RX Interrupt
You should not call high level functions in isr like printf and uart apis. Unless you need very low latency response just let the driver handle the isr.
-
- Posts: 4
- Joined: Tue May 04, 2021 1:10 pm
Re: UART RX Interrupt
Still, I got the same problem. The Interrupt Configuration settings are Right or Wrong?
Thank you
Thank you
-
- Posts: 4
- Joined: Tue May 04, 2021 1:10 pm
Re: UART RX Interrupt
Anyone who has an example code for UART RX Interrupt, share me, please.
Who is online
Users browsing this forum: Baidu [Spider], Google [Bot], tomy983 and 248 guests