UART minimum baudrate????
UART minimum baudrate????
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????
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
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
- martinayotte
- Posts: 141
- Joined: Fri Nov 13, 2015 4:27 pm
Re: UART minimum baudrate????
Wow ! that reminds me the age of Baudot Teletypes, but most of them were 75 baud.
Re: UART minimum baudrate????
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????
Aha, that's a lot simpler than what I had imagined!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.
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
-
- Posts: 10
- Joined: Wed May 31, 2017 4:21 pm
Re: UART minimum baudrate????
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.
Either allowing a 0 length data or a straight set_break command would be nice.
-
- Posts: 9769
- Joined: Thu Nov 26, 2015 4:08 am
Re: UART minimum baudrate????
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????
I also need to start a transmission that starts with a BREAK. Shall I create a github issue?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.
--
Paul.
Paul.
Re: UART minimum baudrate????
I don't think an issue was ever opened, so yes please open one.
Re: UART minimum baudrate????
Thanks.ESP_Angus wrote:I don't think an issue was ever opened, so yes please open one.
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));
--
Paul.
Paul.
Who is online
Users browsing this forum: Baidu [Spider] and 108 guests