Skip to content

esotic UART baudrates won't work (IDFGH-1970) #4166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aster94 opened this issue Oct 6, 2019 · 4 comments
Closed

esotic UART baudrates won't work (IDFGH-1970) #4166

aster94 opened this issue Oct 6, 2019 · 4 comments
Assignees

Comments

@aster94
Copy link

aster94 commented Oct 6, 2019

Environment

  • Development Kit: lolin32
  • IDF version lasted used in the arduino framework
  • Operating System: Windows
  • Power Supply: USB

Problem Description

If i set a custom baudrate in the UART it won't work as expected. At first we tought the problem was in the arduino core (espressif/arduino-esp32#2004), but maybe it is not so I have been suggested to open an iussue here

Code to reproduce this issue

#include <Arduino.h>

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"

#define ECHO_TEST_TXD (UART_PIN_NO_CHANGE)
#define ECHO_TEST_RXD (UART_PIN_NO_CHANGE)
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)

#define BUF_SIZE 1024

void setup()
{
  uart_config_t uart_config = {
      .baud_rate = 10400,
      .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_2, &uart_config);
  uart_set_pin(UART_NUM_2, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
  uart_driver_install(UART_NUM_2, BUF_SIZE * 2, 0, 0, NULL, 0);
}

void loop()
{
  const char *data = "test";
  uart_write_bytes(UART_NUM_2, data, 5);
  delay(2);
}

And here there are two logic analyzer data, the esp-idf.sr comes from the code above
test.zip

@github-actions github-actions bot changed the title esotic UART baudrates won't work esotic UART baudrates won't work (IDFGH-1970) Oct 6, 2019
@negativekelvin
Copy link
Contributor

@koobest 80M/0xFFFFF = 76

@negativekelvin
Copy link
Contributor

It takes 5ms to send 5 bytes at 10400 so if you delay only 2ms you are going to overflow the tx buffer. But other than that, 10400 seems to work fine on uart 1&2.

@aster94
Copy link
Author

aster94 commented Oct 10, 2019

Hi @negativekelvin if your buffer is not corrupted then or my esp32 is broken or i am doing something wrong in the code

This is a sample arduino code

#include <Arduino.h>

HardwareSerial ser(2);

void setup()
{
  ser.begin(10400, SERIAL_8O1);
}

void loop()
{
  ser.print("test");
  delay(100);
}

and here the corresponding version in idf code

#include <Arduino.h>

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"

#define ECHO_TEST_TXD (GPIO_NUM_17)
#define ECHO_TEST_RXD (GPIO_NUM_16)
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)
#define BUF_SIZE 1024

void setup()
{
  uart_config_t uart_config = {
      .baud_rate = 10400,
      .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_1, &uart_config);
  uart_set_pin(UART_NUM_1, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
  uart_driver_install(UART_NUM_1, BUF_SIZE, 0, 0, NULL, 0);
}

void loop()
{
  uart_write_bytes(UART_NUM_1, "test", 4);
  delay(100);
}

I added the two logic traces in this zip file, and the pulseView program says me that there is a frame error
test2.zip

@aster94
Copy link
Author

aster94 commented Apr 6, 2020

on the arduino core it was solved by espressif/arduino-esp32#3664
I am closing since i guess that also here have been solved but feel free to reopen it

@aster94 aster94 closed this as completed Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants