Reading unbuffered data from UART1

psiphi75
Posts: 13
Joined: Thu May 04, 2017 4:45 am

Reading unbuffered data from UART1

Postby psiphi75 » Thu May 04, 2017 4:59 am

I am trying to interface the ESP32 (using UART1) with an RS485 serial interface, this interface is half duplex. I need to be able to read data from the RX on UART1 (RX1), wait for a specific character which signifies the end of transmission from the remote interface and then within 4 milliseconds send my message (obviously on the UART1 TX line).

Is there a way to set an interrupt on each byte received on RX1? Or would I be better to continuously read RX1 waiting for the termination character?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Reading unbuffered data from UART1

Postby WiFive » Thu May 04, 2017 8:34 am

You can interrupt on a # of received chars or a specific command char

Code: Select all

UART_AT_CMD_CHAR_DET_INT: Triggered when the receiver detects the configured at_cmd char.

psiphi75
Posts: 13
Joined: Thu May 04, 2017 4:45 am

Re: Reading unbuffered data from UART1

Postby psiphi75 » Thu May 04, 2017 11:08 am

Thanks for the hint. I ended up using `uart_enable_pattern_det_intr()`, such that the code looked like the following:

Code: Select all

    
    //Set uart pattern detect function.
    uart_enable_pattern_det_intr(EX_UART_NUM, 0xCE, 1, 10000, 10, 10);

    //Create a task to handler UART event from ISR
    xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, 12, NULL);
Where `uart_event_task` is the function to call.

Who is online

Users browsing this forum: Google [Bot], RandomInternetGuy and 140 guests