Is this possible? Check a string on different bauds?

Hi,

Is it possible for the Arduino UNO to read serial data on more than one baud rate(4800, 9600, 38400)? I need it to check different baud rates and then when it finds a matching string on one of the bauds I want it to set a digital out.

Is that possible?

What are you thinking? You get something thru serial, receive it and then check with different baud? If yes, then the answer is NO.

If you want tho wait for a message in 4800, receive it and check it, them wait for a message in 9600, receive it and check it etc. then yes, you can do it.

Can't be done - the conversion of the signal on the pin to the byte of data is done in the hardware UART, at the appropriate baud rate. All you can get out of it is the byte and whether a data framing error occurred (indicating wrong baud rate). By the time you know the baud rate is wrong, the data is no longer there. It doesn't record the pattern on the pin and then look at it once it's gotten a byte's worth, it interprets the data as it's coming in.

You can of course try multiple different UART bauds one at a time, but you'd need data to keep coming in, and you'd miss the data that reached the receiver before you figured out what the baud rate is.

The only way to achieve something like that would be to write your own software serial implementation that stored the data and then played it back. But you'd need... by my count at least 40 bytes of RAM to store that timing data per byte received, and you'd be hard-pressed to process it in time; this would be a challenging piece of code to write, because it's super time sensitive, and I think the processing and memory demands may be prohibitive.

If you had a chip with tons of (hardware - not software) serials, you could tie all the RX pins together, and have each one on a different baud rate, and listen to the one that wasn't getting data framing errors.

Yep.

I want it to cycle through different baud rates to check if any matching data is received.

But I might also make a switch that tells the arduino which baud rate it should check if my first question did not work.

Far from being impossible, what you're asking for is quite easily done, and has been used by zillions of RS232 devices for many decades, assuming the external device periodically sends out a known message. The Arduino simply selects one BAUD rate, then waits long enough to ensure a message SHOULD have been received. If the correct message was received, then it knows what the BAUD rate is. If no message, or an incorrect message, is received, then try again with a different BAUD rate. In many implementations, the "message" is a single ASCII newline character, sent perhaps 3-4 times per second. When the Arduino finds the correct BAUD rate, it sends a short message to the external device to let it know the two devices are ready to communicate.

Regards,
Ray L.

assuming the external device periodically sends out a known message.

And that assumption may not be true.

PaulS:
And that assumption may not be true.

Even knowing a single character is sufficient. Say a comma delimited set of values, or a preamble of a packet, you do not need to know the data, just the meta data. You just need to collect enough data to ensure that what you are looking for has been received at the slowest possible baud.

Ok, thanks for the reply - they have helped me understand a bit more.
The first rev. will only have one baud rate/or an option to choose which baud rate to check with a switch, and when I learn a bit more I might try more baud rates in later revs.

Is it OK to miss a few characters while your hunting for the
right baud or do you need to capture all the characters and determine
the baud rate after.
If it is the first, you can just try different rate values. This was often
done with a know key, such as a return or the letter B.
If you can't miss something, you have to sample the incoming
data and store it in an array as time between edges. Later, you can
find the shortest rate that makes sense.
If sent by hand, there is usually long delays between characters. This makes
it easy to frame the data bits into characters.
Dwight

I just need the first character of the string, let say that is '@'. That means there is data there and I'm happy. If there is another character first I want to lit a red led that means there is data but the wrong string.

We still don't know if the data is repeated so that it can be tested at different baud rates or whether it is only sent once. Please can you clarify that ?

Sorry, yes, it is repeated at least 2-3 every second!

myname:
Sorry, yes, it is repeated at least 2-3 every second!

Then reply #4 applies

Yes, I concluded with that. Do you know of some example code on similar operation, to help me in the right direction?

DrAzzy:
The only way to achieve something like that would be to write your own software serial implementation that stored the data and then played it back. But you'd need... by my count at least 40 bytes of RAM to store that timing data per byte received, and you'd be hard-pressed to process it in time; this would be a challenging piece of code to write, because it's super time sensitive, and I think the processing and memory demands may be prohibitive.

I don't think it's that difficult. You'd only have to store the time difference between the logic level changes, which averages 5 or 6 per byte and can be encoded as one byte each for those baud rates. Processing the data can be done pretty fast. I have a software serial class that does just that -- for only one baud at a time of course -- but it's very efficient and could process all three of those bauds quickly. So you'd need some sort of buffer but I'll bet it would be possible with around 20 bytes total.

But if you don't mind losing characters while doing the auto-baud then it makes more sense to just switch the UART.

You can watch the data on a digital input.
Time how long it remains high and low.
Depending on if the signal is inverted to say an RS232,
would depend on what a mark was and what a space was.
between characters is a Mark it is usually 1.5 or 2 bits wide
then a start bit is sent as a Space bit. This is followed by the lsb
to msb of the data. then followed by the Mark between characters.
@ is 40 hex. That means, after a Mark, there would be Space
bits in a row, including the start bit.
It would be followed by one Mark bit.
If it was 8 bit data, that would be one Mark, one space and then the
Mark between characters ( 1.5 or 2 Marks ).
If 7 bit data, the last data would be 2.5 or 3 Marks.
Measuring the time of the Space signal that is 8 bits long could be
used to determine the baud rate.
Depending on the inversion, it might look like:

1100000001011 ( 8 bit 2 stop at each end )
or if inverted
0011111110100 ( 8 bit 2 stop at each end )

Dwight