Author Topic: Rules for standard UART format  (Read 9878 times)

0 Members and 1 Guest are viewing this topic.

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 11460
  • Country: fi
Re: Rules for standard UART format
« Reply #25 on: January 06, 2023, 07:57:54 am »
One 'gotcha' to note - some UART peripherals (or at least, their documentation) consider the 9th bit to be the parity bit.

Then it is not a "9th bit", it's called parity bit. If some datasheet calls parity-capable UART with max 8-bit data "9-bit", then they are bullshitting. Never seen that, though.

8O1/8E1 and 9N1 are conceptually different even if they have same number of symbols on the line.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4609
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Rules for standard UART format
« Reply #26 on: January 06, 2023, 10:43:56 am »

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 11460
  • Country: fi
Re: Rules for standard UART format
« Reply #27 on: January 06, 2023, 02:50:29 pm »
https://www.st.com/resource/en/reference_manual/rm0090-stm32f405415-stm32f407417-stm32f427437-and-stm32f429439-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

Page 969, section 30.3.1. The last bit transmitted on the wire is labelled a "possible parity bit".

Yes, but that part does support 9-bit data (and they do not call parity bit "data") so what's the problem?

It does not support 9 bit data plus parity, though, but that would be quite rare anyway.
 

Offline pardo-bsso

  • Frequent Contributor
  • **
  • Posts: 266
  • Country: ar
Re: Rules for standard UART format
« Reply #28 on: January 10, 2023, 10:41:02 am »

I understand. The benefit of explicitly giving a number is, you can extend the protocol and make the old nodes ignore messages they do not recognize (unknown message id), by skipping len bytes. If you need to look up the length based on the message id, then you need to know all the messages (their lengths) in advance.

Without knowing the length, you always go out of sync, and getting back in sync would mean losing some messages.

We switched to using Google's Protobuf.

Besides having a single spec for all the messages it takes care of generating c/c++ and python wrappers to do all the parsing.

This may be overkill for the OP question but has saved us from a lot of time otherwise spent debugging and coordinating among teams.
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5400
  • Country: nl
Re: Rules for standard UART format
« Reply #29 on: January 10, 2023, 10:56:18 am »
Then it is not a "9th bit", it's called parity bit. If some datasheet calls parity-capable UART with max 8-bit data "9-bit", then they are bullshitting. Never seen that, though.

It's a bit of a "meh". You may be right "in theory", but it is the practice that matters.
From what I remember of stm32, they do support 9 bit, or parity, but not at the same time.

When parity is "odd" or "even", it has a clear function (does anyone even use parity?) Sometimes a parity of "mark" or "space" is used, and then the distinction becomes minimal.

And when it comes to microcontrollers. when interfacing with the outside world, only the signals on the pins matter. It does not matter whether the datasheet claims whether it is a "9th bit" or a "parity bit". You are free to abuse uC features to generate the signals you need for your application. The biggest problem here is that if you rely more on obscure features of your microcontroller, your code becomes less portable.
 

Offline MIS42N

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: au
Re: Rules for standard UART format
« Reply #30 on: January 10, 2023, 12:31:00 pm »
What are the rules for standard UART ?

Suppose we have two different size of microcontroller's one is 32 bits long and other is 8 bit long. We want to transfer one byte from 32 MCU to 8 bit MCU using UART over RS232 interface.

UART is configured for 9600,N,8,1

Can 32 bit MCU tranfer 1byte to 8 bit MCU using UART?

A 'standard' UART will signal at a particular voltage, and 9600 is the rate per second at which bits are transmitted. The A in UART is Asynchronous - a transmission of a byte (configuring for 8 data bits) starts at an arbitrary time after the completion of the transmission of the previous byte. UART output is usually high when idle, and bits are 1 = high, 0 = low voltage. In the case of sending bytes, every byte is sent with a start bit which is a 0, and a stop bit which is 1. Each bit is signalled for 1/9600th of a second (about 104us) except the stop bit which is a minimum of 104us but morphs into the idle state if there is a delay before the next byte. Bits are sent most significant first. So it requires 10 bit times to send 8 data bits.

For UART to UART communication, the only compatibility issue is the voltages. Connecting the UART of a 5V device to the UART of a 3.3V device is asking for trouble (it does work sometimes).

The OP specified RS232. To get RS232 signals from a UART it is necessary to use a TTL to RS232 converter with both UARTs. RS232 signals are -ve for idle or 1 and +ve for a 0 (opposite polarity to UART) and a value between -3 and +3V should be ignored (although many receivers will take 0V as idle or 1). The voltages for RS232 are defined by the standard so any RS232 transmitter should be compatible with any RS232 receiver.

As others have pointed out, it is unnecessary to use RS232 signalling unless required by some device. UART to UART just requires a level shifter if the two devices run at different voltages.

So yes, just about any UART can send a byte to another UART.
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 11460
  • Country: fi
Re: Rules for standard UART format
« Reply #31 on: January 10, 2023, 02:34:31 pm »
It's a bit of a "meh". You may be right "in theory", but it is the practice that matters.

I also covered practice by saying, never seen that in real life. But by all means, if you know a MCU or standalone UART which explicitly calls "9-bit" in documentation yet is unable to send or receive 9-bit data, let us know.

STM32 surely can, but as usual, both 9-bit data and parity features are not available simultaneously. This is normal; anyone who has been bitten a few times knows that any combination of two or more front page features might not be available at the same time, and will recheck if you can have both features X and Y simultaneously.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 8354
  • Country: fi
    • My home page and email address
Re: Rules for standard UART format
« Reply #32 on: January 11, 2023, 03:34:08 pm »
I must admit I am surprised to see it so vehemently disagreed as to what is "standard" for an UART transceiver.  I guess I have been pampered with the support I've had with the microcontrollers I've used!

NXP i.MX RT1062 (as used on Teensy 4.x) supports 7 to 10 bit data (the transmitter and receiver have 9 to 13 bit shift registers), and internally supports both idle and break "characters" (break length being 9 to 15 bit times, depending on the relevant settings), and even hardware flow control (RTS/CTS).
Even Atmel (now Microchip) ATmega32U4, an 8-bit AVR with native USB support, supports 5 to 9 bit data, all with no or even or odd parity, and with one or two stop bits (the datasheet explicitly mentions all 30 combinations are supported).  The other 32-bit NXP chips I often use (specifically on Teensy LC and 3.x) have similar support.

[For framing messages] one can use a simple a SLIP frame format: https://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol
There are more efficient, but more complex implementations for creating this kind of soft framings.
As mentioned, COBS or Consistent Overhead Byte Stuffing is one.

One could say that using the BREAK condition –– which is basically the same size as a normal serial data frame but one that is separate from all valid data frames –– would be even simpler, and just as efficient as COBS for framing.  Unfortunately, not all UART/USART implementations support sending or receiving BREAK conditions/characters in a sensible manner.

I personally prefer a variant of SLIP with 1/N maximum overhead (depending on implementation complexity) and minimal buffering (four bytes for 33% maximum overhead).  The major difference to SLIP and COBS is that my variant allows multiple frame byte values that will not occur in the data.  (There are also multiple byte values that always begin an escape sequence.)
I developed the variant for an use case where I wanted to multiplex multiple logical byte streams onto a single byte stream with minimal latency (thus minimal buffering and very short uninterruptible sequences) and minimal work for both multiplexing and demultiplexing.

Using an extra bit to differentiate structure and data bytes is an interesting approach.  It means data can be sent as-is, without any need for escaping.  However, the extra bit does mean something like 8% to 10% constant overhead (because each UART data frame will typically have at least a START bit and one or two STOP bits in addition to the data bits), plus the frame structuring bytes on top.  Of course, if one has just two byte streams to multiplex, then the extra bit (or bits!) could be used to indicate the stream the data bits are part of.

The two-stream-multiplexing by an extra bit reminds me of the SPI bus variant many OLED and small TFT display module driver chips (ILI9341, ST7735S, ST7789, etc.) use for (serial) communications with a microcontroller: they have a separate Data/Command signal indicating whether the current/next byte is a new command, or data related to the previous command.
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5400
  • Country: nl
Re: Rules for standard UART format
« Reply #33 on: January 12, 2023, 01:13:18 am »
It's a bit of a "meh". You may be right "in theory", but it is the practice that matters.

I also covered practice by saying, never seen that in real life. But by all means, if you know a MCU or standalone UART which explicitly calls "9-bit" in documentation yet is unable to send or receive 9-bit data, let us know.

This reminds me of programming in assembly (which was lukicly long ago.
Some uC's use a "trick" for clearing a gegister, by XOR-ing a register with itself.

Other uC's had a specially defined opcode, documented an all for clearing a register. So I was curious and looked at the machinecode, and they were the same. But it still was useful, as the opcode to clear a register made a clear statement to the intention of the programmer.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->