Issue in UART ESP32 with interrupt
Posted: Mon Jun 07, 2021 9:44 am
Hello,
I am trying to use UART in interrupt mode but when I am receiving anything, the controller keeps on resetting.
I am using Visual studio 2015 with GCC version 8.4.0, GDB version 8.1.0 and esp-idf v4.3.
At first uart_reg.h file was not inlcuded but when I added the header it flagged pop-up attached in image.
Initialization for UART
The UART transmit function is same as in uart async task example in esp-idf.
UART RX ISR handle code :
I am trying to use UART in interrupt mode but when I am receiving anything, the controller keeps on resetting.
I am using Visual studio 2015 with GCC version 8.4.0, GDB version 8.1.0 and esp-idf v4.3.
At first uart_reg.h file was not inlcuded but when I added the header it flagged pop-up attached in image.
Initialization for UART
Code: Select all
void uart_Init(void)
{
uart_config_t uart1_conf;
uart1_conf.baud_rate = 115200;
uart1_conf.data_bits = UART_DATA_8_BITS;
uart1_conf.parity = UART_PARITY_DISABLE;
uart1_conf.stop_bits = UART_STOP_BITS_1;
uart1_conf.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
uart1_conf.source_clk = UART_SCLK_APB;
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0));
ESP_ERROR_CHECK(uart_param_config(UART_NUM_1, &uart1_conf));
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, GPIO_NUM_21, GPIO_NUM_22, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
ESP_ERROR_CHECK(uart_isr_free(UART_NUM_1));
ESP_ERROR_CHECK(uart_isr_register(UART_NUM_1, uart_intr_handle, NULL, ESP_INTR_FLAG_IRAM, &handle_console)); // register new UART subroutine
ESP_ERROR_CHECK(uart_enable_rx_intr(UART_NUM_1)); // enable RX interrupt
}
UART RX ISR handle code :
Code: Select all
void uart_intr_handle(void *arg)
{
data = (uint8_t*) malloc(BUF_SIZE + 1);
int rxBytes = uart_read_bytes(UART_NUM_1, data, BUF_SIZE, 1000 / portTICK_RATE_MS);
if (rxBytes > 0) {
data[rxBytes] = 0;
ESP_LOGI(RX_TASK_TAG, "Read %d bytes: '%s'", rxBytes, data);
ESP_LOG_BUFFER_HEXDUMP(RX_TASK_TAG, data, rxBytes, ESP_LOG_INFO);
}
free(data);
// after reading bytes from buffer clear UART interrupt status
uart_clear_intr_status(UART_NUM_1, UART_RXFIFO_FULL_INT_CLR | UART_RXFIFO_TOUT_INT_CLR);
}