Re: UART Communication problems at 921600
Posted: Wed Nov 13, 2019 7:00 am
Hi, LukeSkyWireLukeSkyWire wrote: ↑Wed Jun 20, 2018 11:05 amWhat I have noticed however is if I send 1400 bytes the uart_read_bytes returns a value in the range of 1390.
If I send 600 bytes I get a len of approx 596.
That's all right with me if we could get it working without errors in the uart communication.
Is this the official maximum baudrate achievable without hw flow control? Could you link the documentation specifying this limit? I only remember seeing the 5M limit and no requirement for hw flow control connections mention, but I could be wrong.ESP_houwenxiang wrote: ↑Thu Nov 14, 2019 7:40 amHi, LukeSkyWireLukeSkyWire wrote: ↑Wed Jun 20, 2018 11:05 amWhat I have noticed however is if I send 1400 bytes the uart_read_bytes returns a value in the range of 1390.
If I send 600 bytes I get a len of approx 596.
Have you enabled hardware flow control? At 1M baud, the CPU can read out the data in fifo in time. But At 2M baud-rate, the CPU cannot read out the data in fifo in time, resulting in data loss. When enable the flow control, the baud-rate can reach 5M.
thanks !!
Code: Select all
#define UART_NUM (UART_NUM_1)
#define BAUD_RATE (921600)
#define RX_BUF_SIZE (100000)
void uart_Init()
{
const uart_config_t uart_config = {
.baud_rate = BAUD_RATE,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_param_config(UART_NUM, &uart_config);
uart_intr_config_t uart_intr = {
.intr_enable_mask = UART_RXFIFO_FULL_INT_ENA_M
| UART_RXFIFO_TOUT_INT_ENA_M
| UART_FRM_ERR_INT_ENA_M
| UART_RXFIFO_OVF_INT_ENA_M
| UART_BRK_DET_INT_ENA_M
| UART_PARITY_ERR_INT_ENA_M
| UART_GLITCH_DET_INT_ENA_M,
.rxfifo_full_thresh = 1, //-----> changed it from 1 to 64 still data missing
.rx_timeout_thresh = UART_RX_TOUT_THRHD,
.txfifo_empty_intr_thresh = UART_TXFIFO_EMPTY_THRHD
};
uart_intr_config(UART_NUM, &uart_intr);
uart_set_pin(UART_NUM, TX_PIN, RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
esp_err_t ret = uart_driver_install(UART_NUM, RX_BUF_SIZE, 0, 5, &uartQueueHandle, 0);
if (ret!== ESP_OK) {
systemRestart();
}
uart_flush(UART_NUM_1);
}
void serial_read(void *arg)
{
uint8_t* dataSerial = (uint8_t*) malloc(dataSize);
uint32_t read_buff_size = 49000;
size_t b_len =0;
uint8_t * rx_data = (char *) heap_caps_malloc(read_buff_size, MALLOC_CAP_SPIRAM);
while ( 1 )
{
send_cmd();
while( ( b_len < read_buff_size ) && ( time_out < 20 ) )
{
ESP_LOG_BUFFER_HEXDUMP("HEXDUMP", cmd_struct.cmd_buff,cmd_struct.config.cmd_len, ESP_LOG_INFO);
ESP_LOGI(SCANNER_TAG, "b_len : %d", b_len);
uart_get_buffered_data_len( UART_NUM, &b_len );
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;
msDelay(1000);
time_out++;
}
uart_read_bytes(UART_NUM, &rx_data, read_buff_size, 0)
processdata(rx_data);
msDelay(1);
}
vTaskDelete(NULL);
}
void app_main(void)
{
uart_Init();
while ( isuart != pdPASS) { // wait till task is created
isuart = xTaskCreatePinnedToCore(serial_read, "serial_read", 1024*12, NULL, 22, &scanner_t, CORE_ONE);
ESP_LOGI(NIBLEWAY_ONLINE, "scanner Task, pdFAIL");
msDelay(100);
}
}