RS-485 half-duplex extra byte received.

sramberg2
Posts: 9
Joined: Tue Jul 20, 2021 9:35 pm

RS-485 half-duplex extra byte received.

Postby sramberg2 » Fri Jul 23, 2021 10:31 pm

IDF4.3
Sending 7 bytes out UART2 configured as RS485 Half-duplex every 80ms at 115200 baudrate.
While debugging this issue, https://www.esp32.com/viewtopic.php?f=13&t=21835
Occasionally I would see a data byte in the RX FIFO following a transmission. The byte was always 0x00.
I modified the TX DONE interrupt, in UART.c, to disable the RX FIFO flushing and I received the extra byte close to 100% of the time. It appears that the RX FIFO flush would remove this extra byte most of the time.
  1.         } else if(uart_intr_status & UART_INTR_TX_DONE) {
  2.             if (UART_IS_MODE_SET(uart_num, UART_MODE_RS485_HALF_DUPLEX) && uart_hal_is_tx_idle(&(uart_context[uart_num].hal)) != true) {
  3.                 // The TX_DONE interrupt is triggered but transmit is active
  4.                 // then postpone interrupt processing for next interrupt
  5.                 uart_event.type = UART_EVENT_MAX;
  6.             } else {
  7.                 // Workaround for RS485: If the RS485 half duplex mode is active
  8.                 // and transmitter is in idle state then reset received buffer and reset RTS pin
  9.                 // skip this behavior for other UART modes
  10.                 UART_ENTER_CRITICAL_ISR(&(uart_context[uart_num].spinlock));
  11.                 uart_hal_disable_intr_mask(&(uart_context[uart_num].hal), UART_INTR_TX_DONE);
  12.                 if (UART_IS_MODE_SET(uart_num, UART_MODE_RS485_HALF_DUPLEX)) {
  13. //SRR 7/23/21                    uart_hal_rxfifo_rst(&(uart_context[uart_num].hal));
  14.                     uart_hal_set_rts(&(uart_context[uart_num].hal), 1);
  15.                 }
  16.                 UART_EXIT_CRITICAL_ISR(&(uart_context[uart_num].spinlock));
  17.                 uart_hal_clr_intsts_mask(&(uart_context[uart_num].hal), UART_INTR_TX_DONE);
  18.                 xSemaphoreGiveFromISR(p_uart_obj[uart_num]->tx_done_sem, &HPTaskAwoken);
  19.             }
  20.         } else {
I do not see the extra byte on the output of the RS-485 driver.

Any idea on how to prevent this extra byte?

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

Re: RS-485 half-duplex extra byte received.

Postby WiFive » Fri Jul 23, 2021 10:41 pm

Did you try moving it after uart_hal_set_rts

Who is online

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