Page 1 of 2

UART minimum baudrate????

Posted: Fri Mar 17, 2017 7:55 pm
by minDark
Hello to everyone! I need to know what is the minimum baud rate for the UART port. I have an OBD communication board and i need a baudrate of 5 BAUD, 7O1 format. I don't want to use software bit-banging or timers. Is it posible to set a baudrate of 5, if the main CLK is 240MHz??

Re: UART minimum baudrate????

Posted: Mon Mar 20, 2017 2:58 am
by ESP_Angus
Wow, 5bps! With some practice you could almost whistle that baud rate!

Unfortunately I don't think this is supported via the UART peripheral, at least not yet. UART master clock is the APB clock which is 80MHz by default. The integer portion of the clock divider register is 20 bits wide, which gives a theoretical minimum speed of 76bps (I'm not certain a rate this low is actually supported either, would have to check). You would you need a 24 bit divider to divide 80MHz down to 5Hz.

In future I think we will support other APB clock frequencies and/or UART clock sources, but we don't support this right now.

The good news is, such a low bitrate should be very straightforward to bit-bang read as a "soft UART". I'd suggest using a GPIO interrupt to detect a start condition, and then enable a "timer group" timer to configure a timer interrupt, and read the pin as a GPIO from the ISR. At 240MHz you will have lots of spare time between each bit period. :)

Angus

Re: UART minimum baudrate????

Posted: Mon Mar 20, 2017 7:14 pm
by martinayotte
Wow ! that reminds me the age of Baudot Teletypes, but most of them were 75 baud.

Re: UART minimum baudrate????

Posted: Mon Mar 27, 2017 8:27 am
by minDark
Thanks for answer! The 5baud will be TX only for a single byte and then switch the baudrate to 9600 or 10400. So no interrupt pin, just send a single byte @ 5 BAUD and then switch. For a regular serial port on windows i'm using break signal. ESP32 can send break signal for a specified length on UART? In IDF source code i see a function uart_set_break() witch should do the right thing.

Re: UART minimum baudrate????

Posted: Mon Mar 27, 2017 11:21 pm
by ESP_Angus
minDark wrote:ESP32 can send break signal for a specified length on UART? In IDF source code i see a function uart_set_break() witch should do the right thing.
Aha, that's a lot simpler than what I had imagined!

Try the uart_write_bytes_with_break() function, with the number of bytes set to zero:
http://esp-idf.readthedocs.io/en/latest ... Kc6size_ti

Re: UART minimum baudrate????

Posted: Wed May 31, 2017 4:28 pm
by benpeoples
The uart_write_byte_with_break checks the length of the data and spits out an error on size 0. Currently looking for a solution for this, I use a protocol that starts packets with a BREAK...

Either allowing a 0 length data or a straight set_break command would be nice.

Re: UART minimum baudrate????

Posted: Fri Jun 02, 2017 2:03 am
by ESP_Sprite
That's a bug, methinks. Could you do us a favour and report this on https://github.com/espressif/esp-idf/issues ? We have better tracking of issues there than on the forums here.

Re: UART minimum baudrate????

Posted: Thu Aug 02, 2018 2:27 pm
by papaluna
benpeoples wrote:The uart_write_byte_with_break checks the length of the data and spits out an error on size 0. Currently looking for a solution for this, I use a protocol that starts packets with a BREAK... Either allowing a 0 length data or a straight set_break command would be nice.
I also need to start a transmission that starts with a BREAK. Shall I create a github issue?

Re: UART minimum baudrate????

Posted: Fri Aug 03, 2018 5:58 am
by ESP_Angus
I don't think an issue was ever opened, so yes please open one.

Re: UART minimum baudrate????

Posted: Fri Aug 03, 2018 8:05 pm
by papaluna
ESP_Angus wrote:I don't think an issue was ever opened, so yes please open one.
Thanks.

A similar issue already exists https://github.com/espressif/esp-idf/issues/703 According to @costaud, the hardware apparently does not support sending a BREAK before a data transmission, and the UART Driver does not support sending empty data using uart_write_bytes_with_break().

A possible solution to send a BREAK condition (https://en.wikipedia.org/wiki/Universal ... _condition) can be achieved using uart_set_line_inverse() and so inverting the TX idle signal level from HIGH to LOW for a specific duration, and then reverting back to the original setup. The result looks good on the logic analyzer.

An example for an UART of 9600 baud: transmitting 1 character of 10 bits results in 10 frames and takes +-1millisec so a BREAK condition must set the signal Low for at least > 1 millisec and then set it High again.

Code: Select all

    uart_set_line_inverse(MY_UART_NUM, UART_INVERSE_TXD);
    ets_delay_us(2 * 1000);
    uart_set_line_inverse(MY_UART_NUM, UART_INVERSE_DISABLE);
    char autobaud_string[2] = { 0x55, '\0' };
    f_retval = uart_write_bytes(MY_UART_NUM, autobaud_string, strlen(autobaud_string));
This code works fine for the Microchip SN2483 Lora module to wake it up from sleep mode.