UART ISR handler

balix53
Posts: 27
Joined: Mon Jan 21, 2019 8:47 am

UART ISR handler

Postby balix53 » 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:

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);
	}
}
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:

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));
Regards,

Benjamin

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: UART ISR handler

Postby ESP_Sprite » Fri Jan 07, 2022 1:35 am

I can't use queues or FreeRTOS tasks
That is an odd restriction... Why not?

Looking at what uart_driver_install does, you may need to call 'uart_module_enable' before doing anything else... it could be that your UART still is clockgated and as such doesn't do anything.

wangxy
Posts: 7
Joined: Thu Jan 06, 2022 6:01 am

Re: UART ISR handler

Postby wangxy » Mon Jan 10, 2022 8:41 am

I have the same problem. ESP32-S2 IDFV4.2.2
UART0.png
UART0.png (56.22 KiB) Viewed 6608 times

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: UART ISR handler

Postby ESP_Sprite » Tue Jan 11, 2022 1:30 am

That is not the same error. Please use a separate post for this.

balix53
Posts: 27
Joined: Mon Jan 21, 2019 8:47 am

Re: UART ISR handler

Postby balix53 » Tue Jan 11, 2022 1:35 pm

ESP_Sprite wrote:
Fri Jan 07, 2022 1:35 am
Looking at what uart_driver_install does, you may need to call 'uart_module_enable' before doing anything else... it could be that your UART still is clockgated and as such doesn't do anything.
I tried adding the UART module enable, still nothing on the output.

We will finally roll back to the previous implementation and use a task to capture the events (like in the UART event example).

Who is online

Users browsing this forum: Bing [Bot] and 339 guests