RS485 Enable pin issue
Posted: Mon Jul 05, 2021 12:45 am
I have set up a UART on ESP32 that sends RS485 data every few hundred ms.
After a long time (it might be several hours or a couple of days), the ENABLE pin stops working correctly and I loose connection to remote devices on the RS485 bus, it does not recover until I reset the power supply. At first I thought it was a hardware issue but when I looked on a scope the ENABLE pin was set high for entire duration of data packet ok for long time but when it plays up the enable goes high for a short period of time before the data packet and goes low before data is sent.
Is there any known issue with the UART driver software that could cause this? Should I disable the enable function and manually toggle the enable using GPIO during transmission instead?
My config is below.
[code]
#define RX_BUFFER_SIZE (128*2)
#define rs485_uart (UART_NUM_1)
#define RS485_TXD_PIN (27)
#define RS485_RXD_PIN (13)
#define RS485_EN_PIN (14)
void init_rs485_uart(void)
{
const uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
};
uart_param_config(rs485_uart, &uart_config);
uart_set_pin(rs485_uart, RS485_TXD_PIN, RS485_RXD_PIN, RS485_EN_PIN, UART_PIN_NO_CHANGE);
ESP_ERROR_CHECK(uart_driver_install(rs485_uart, RX_BUFFER_SIZE,0,UART_QUEUE_SIZE,&uart_queue,0));
ESP_ERROR_CHECK(uart_set_mode(rs485_uart, UART_MODE_RS485_HALF_DUPLEX));
uart_set_rx_timeout(rs485_uart,UART_BREAK_TIME);
//uart_set_always_rx_timeout(rs485_uart,true);
xTaskCreate(uart_event_task,"uart event task",2048,NULL,20,NULL);
}
int send_rs845_uart_data(char *command,int numbytes)
{
uart_write_bytes(rs485_uart, command, numbytes);
return true;
}
[/code]
After a long time (it might be several hours or a couple of days), the ENABLE pin stops working correctly and I loose connection to remote devices on the RS485 bus, it does not recover until I reset the power supply. At first I thought it was a hardware issue but when I looked on a scope the ENABLE pin was set high for entire duration of data packet ok for long time but when it plays up the enable goes high for a short period of time before the data packet and goes low before data is sent.
Is there any known issue with the UART driver software that could cause this? Should I disable the enable function and manually toggle the enable using GPIO during transmission instead?
My config is below.
[code]
#define RX_BUFFER_SIZE (128*2)
#define rs485_uart (UART_NUM_1)
#define RS485_TXD_PIN (27)
#define RS485_RXD_PIN (13)
#define RS485_EN_PIN (14)
void init_rs485_uart(void)
{
const uart_config_t uart_config = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_APB,
};
uart_param_config(rs485_uart, &uart_config);
uart_set_pin(rs485_uart, RS485_TXD_PIN, RS485_RXD_PIN, RS485_EN_PIN, UART_PIN_NO_CHANGE);
ESP_ERROR_CHECK(uart_driver_install(rs485_uart, RX_BUFFER_SIZE,0,UART_QUEUE_SIZE,&uart_queue,0));
ESP_ERROR_CHECK(uart_set_mode(rs485_uart, UART_MODE_RS485_HALF_DUPLEX));
uart_set_rx_timeout(rs485_uart,UART_BREAK_TIME);
//uart_set_always_rx_timeout(rs485_uart,true);
xTaskCreate(uart_event_task,"uart event task",2048,NULL,20,NULL);
}
int send_rs845_uart_data(char *command,int numbytes)
{
uart_write_bytes(rs485_uart, command, numbytes);
return true;
}
[/code]