I'm experiencing an abnormal behaviour regarding receiving a message on UART1 .
The ESP32 is connected through a UART to another processor, an Cortex-M3, that acts as a specialised measuring system.
The ESP32 sends a message to the Cortex-M3 specifying what measurement should be made and its parameters.
When the measurement is done the Cortex-M3 sends a message back to the ESP32 with the measurement results.
It is here that the problem resides. The ESP32 does not seem to cope with the speed of the Cortex-M3.
I'm using a baudrate of 57600. I have tried with 19200 and the problem persists.
The problem is solved when on the Cortex-M3 I put a delay of about 1ms between consecutive message bytes.
Somehow the FIFO or ring buffer mechanisms on the ESP32 do not seem to be working properly...
This is the code to initialise the UART:
Code: Select all
esp_err_t UART_Initialise (uart_port_t port, gpio_num_t pinTXD, gpio_num_t pinRXD, unsigned int bufferSize, uint32_t baudrate)
{
esp_err_t err = ESP_OK;
if ( UART_Initialised )
return ESP_OK;
UART_port = port;
/// ESP IDF compatible UART configuration struct
uart_config_t uartConfig;
uartConfig.baud_rate = baudrate;
uartConfig.data_bits = UART_DATA_8_BITS;
uartConfig.parity = UART_PARITY_DISABLE;
uartConfig.stop_bits = UART_STOP_BITS_1;
uartConfig.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
uartConfig.rx_flow_ctrl_thresh = 0;
uartConfig.use_ref_tick = false;
err = uart_param_config (UART_port, &uartConfig);
while(err != ESP_OK);
if ( err != ESP_OK)
return ESP_FAIL;
err = uart_set_pin (UART_port, pinTXD, pinRXD, UART_PIN_NO_CHANGE/*pinRTS*/, UART_PIN_NO_CHANGE/*pinCTS*/);
if ( err != ESP_OK)
return ESP_FAIL;
err = uart_driver_install (UART_port, bufferSize, 0, 0, NULL, 0);
if ( err != ESP_OK)
return ESP_FAIL;
UART_Initialised = true;
return ESP_OK;
}
Code: Select all
res = UART_Initialise ( UART_NUM_1, UART_TX_PIN, UART_RX_PIN, 1000/*buffer size*/, 57600/*baudrate*/ );
Code: Select all
uint8_t frame_byte;
while (true)
{
uint16_t ticks_to_wait = 10;
rd = uart_read_bytes (UART_port, &frame_byte, 1/*length*/, ticks_to_wait);
if ( rd == -1 ) return ESP_FAIL;
if ( rd == 1 ) break;
time_waited += ticks_to_wait;
if ( time_waited >= timeout_ticks ) return ESP_FAIL;
}
Any ideas how to diagnose this?
Are there any examples that use this type of protocol communication?
thanks