UART ISR handler
Posted: Thu Jan 06, 2022 4:44 pm
Hi,
I'm trying to develop an ISR handler for UART communication (RX only).
I can't use queues or FreeRTOS tasks so the example provided in the ESP IDF won't do the trick (although I have tested it and it works well).
I also have seen here on this forum a lot of topics and messages discussing this code: https://github.com/theElementZero/ESP32 ... nterrupt.c
But it doesn't work for me either.
So the last thing I have done is to try to use the HAL UART APIs like in the UART driver default handler: https://github.com/espressif/esp-idf/bl ... ver/uart.c
My handler looks like this:
The "notify_data_received" function should wake another task on the system and display the data received on the logs output but I never see anything.
To see if there was indeed an interrupt I used a semaphore that is given in the ISR but it didn't work as well.
Maybe my ISR register is wrong? Here is how I've done it:
Regards,
Benjamin
I'm trying to develop an ISR handler for UART communication (RX only).
I can't use queues or FreeRTOS tasks so the example provided in the ESP IDF won't do the trick (although I have tested it and it works well).
I also have seen here on this forum a lot of topics and messages discussing this code: https://github.com/theElementZero/ESP32 ... nterrupt.c
But it doesn't work for me either.
So the last thing I have done is to try to use the HAL UART APIs like in the UART driver default handler: https://github.com/espressif/esp-idf/bl ... ver/uart.c
My handler looks like this:
Code: Select all
static void IRAM_ATTR uart_isr_handler(void* arg) {
uint32_t interrupt_status = uart_hal_get_intsts_mask(&hal_context);
if ((interrupt_status & UART_INTR_RXFIFO_TOUT) || (interrupt_status & UART_INTR_RXFIFO_FULL)) {
int32_t rxfifo_len = uart_hal_get_rxfifo_len(&hal_context);
uart_hal_read_rxfifo(&hal_context, RX_BUFFER, &rxfifo_len);
for (uint32_t i = 0; i < rxfifo_len; i++) {
notify_data_received(arg, RX_BUFFER[i]);
}
uart_hal_clr_intsts_mask(&hal_context, UART_RXFIFO_FULL_INT_CLR | UART_RXFIFO_TOUT_INT_CLR);
}
}
To see if there was indeed an interrupt I used a semaphore that is given in the ISR but it didn't work as well.
Maybe my ISR register is wrong? Here is how I've done it:
Code: Select all
uart_config_t config = {
.baud_rate = baudrate,
.data_bits = uart_data_bits,
.stop_bits = uart_stop_bits,
.parity = uart_parity,
};
ESP_ERROR_CHECK(uart_param_config(UART_NUM, &config));
ESP_ERROR_CHECK(uart_set_pin(UART_NUM, UART_TX, UART_RX, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_isr_register(UART_NUM, uart_isr_handler, (void*) arg, 0, NULL));
ESP_ERROR_CHECK(uart_enable_rx_intr(UART_NUM));
Benjamin