I have a custom board with an ESP32-WROOM Module on it. When my board is running for ~30min and more the ESP32 does not receive any more UART messages. I was able to verify, that messages are sent from my board and an answer is sent back, but the ESP does not register anything.
Code: Select all
bool ModbusRTUMaster::readInputRegisters(uint8_t id, uint16_t startAddress, uint16_t* buf, uint16_t quantity) {
const uint8_t functionCode = 4;
if (id < 1 || id > 247 || !buf || quantity == 0 || quantity > 125) return false;
_buf[0] = id;
_buf[1] = functionCode;
_buf[2] = highByte(startAddress);
_buf[3] = lowByte(startAddress);
_buf[4] = highByte(quantity);
_buf[5] = lowByte(quantity);
_writeRequest(6);
uint32_t startTime = esp_timer_get_time();
size_t buffered_len;
uart_get_buffered_data_len(_uart_num, &buffered_len);
while (esp_timer_get_time() - startTime < 50000 && buffered_len < _bytesSent && _bytesSent > 0)
{
esp_err_t error = uart_get_buffered_data_len(_uart_num, &buffered_len);
if (error != ESP_OK)
{
uart_driver_delete(_uart_num);
uart_config_t uart_config = {
.baud_rate = 9600,
.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(_uart_num, &uart_config);
uart_set_pin(_uart_num, GPIO_NUM_1, GPIO_NUM_3, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
uart_driver_install(_uart_num, 512, 0, 0, NULL, 0);
}
}
startTime = esp_timer_get_time();
while (esp_timer_get_time() - startTime < 100000 && buffered_len < 2)
{
uart_get_buffered_data_len(_uart_num, &buffered_len);
}
//vTaskDelay(pdMS_TO_TICKS(30)); // Delay anstelle von delay()
uint16_t responseLength = _readResponse(id, functionCode);
if (responseLength != (uint16_t)(3 + quantity * 2) || _buf[2] != quantity * 2) return false;
for (uint16_t i = 0; i < quantity; i++) {
buf[i] = _bytesToWord(_buf[4 + i * 2], _buf[3 + i * 2]);
}
return true;
}