1
votes

I am trying to run UART1 interrupt on ESP32 WROVER but in process of compilation I get:

../main/scan.c: In function 'uart_intr_handle': ../main/scan.c:195:12: error: 'UART1' undeclared (first use in this function)    status = UART1.int_st.val; // read UART interrupt Status
            ^~~~~ ../main/scan.c:195:12: note: each undeclared identifier is reported only once for each function it appears in ../main/scan.c:205:37: error: 'UART_RXFIFO_FULL_INT_CLR' undeclared (first use in this function); did you mean 'UART_FIFO_LEN'?   uart_clear_intr_status(UART_NUM_1, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
                                     ^~~~~~~~~~~~~~~~~~~~~~~~
                                     UART_FIFO_LEN ../main/scan.c:205:62: error: 'UART_RXFIFO_TOUT_INT_CLR' undeclared (first use in this function); did you mean 'SPI_IN_DONE_INT_CLR'?   uart_clear_intr_status(UART_NUM_1, UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
                                                              ^~~~~~~~~~~~~~~~~~~~~~~~

                                                      SPI_IN_DONE_INT_CLR

Code that is generating this is:

/*
 * Define UART interrupt subroutine to ackowledge interrupt
 */
static void IRAM_ATTR uart_intr_handle(void *arg)
{
  uint16_t rx_fifo_len, status;
  uint16_t i;
  BaseType_t xHigherPriorityTaskWoken;

  status = UART1.int_st.val; // read UART interrupt Status
  rx_fifo_len = UART1.status.rxfifo_cnt; // read number of bytes in UART buffer

  while(rx_fifo_len){
   rxbuf[i++] = UART1.fifo.rw_byte; // read all bytes
   rx_fifo_len--;
 }

 // 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);

// a test code or debug code to indicate UART receives successfully,
// you can redirect received byte as echo also
 //uart_write_bytes(EX_UART_NUM, (const char*) "RX Done", 7);

}

Example comes from: https://github.com/theElementZero/ESP32-UART-interrupt-handling/blob/master/uart_interrupt.c

What should I do to get UART1 variable?

Tnx for helping out!

1
did you make sure you included the right headers? Does it work with UART0? Maybe there was a recent renamingChristian B.
Yes, I did the same as in the example.user505160
and....does it work for UART0?Christian B.

1 Answers

1
votes

Add this header:

#if CONFIG_IDF_TARGET_ESP32
    #include "esp32/rom/uart.h"
#elif CONFIG_IDF_TARGET_ESP32S2
    #include "esp32s2/rom/uart.h"
#endif