ESP32 UART прерывание - PullRequest
       118

ESP32 UART прерывание

1 голос
/ 18 июня 2020

Я пытаюсь запустить прерывание UART1 на ESP32 WROVER, но в процессе компиляции я получаю:

../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

Код, который генерирует это:

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

}

Пример из: https://github.com/theElementZero/ESP32-UART-interrupt-handling/blob/master/uart_interrupt.c

Что мне делать, чтобы получить переменную UART1?

Tnx за помощь!

1 Ответ

0 голосов
/ 18 августа 2020

Добавьте этот заголовок:

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