115200 baud UART

Go To Last Post
34 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I have been having trouble talking to 16MHz mega's at 115200 BAUD.  Talking to a PuTTY window through an FTDI USB-serial chip gives me garbage on the screen, if anything at all.  I know my FTDI board will go at 115.2 kBAUD from using it with a WiFi module that went at that rate.  The  mega data sheets say the UART error rate is -3.5% for 115200 baud @ 16 MHz (0.2% at 9600 BAUD), but the error rate is 0% for all BAUD rates up to 230.4k @ 18.4320 MHz.  I'm wondering if I change out the 16 MHz crystal with an 18.4320 MHz crystal, my mega's will talk over UART at 115200 baud.

 

I am talking to an 18 channel ams AS7265x photo detector set, and it wants to talk UART at 115200 BAUD to set the scalars to calibrate the ADC's.

 

I know somebody out there knows the answer to this.

Last Edited: Mon. Feb 11, 2019 - 01:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  I'm wondering if I change out the 16 MHz crystal with an 18.4320 MHz crystal, my mega's will talk over UART at 115200 baud.

Depends WHICH mega, if it's a 20MHz chip then yes, otherwise if it's a 16MHz chip you need to go to 14.7456MHz just like the datasheet shows.

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Switch to 2X mode, it will get you to within 2.13%.  Might work, might not, depending on the other side.

 

(16,000,000 / 8) / 115,200 = 17.361111111, so a UBRR value of 16 gets you ((16,000,000 / 8) / (16 + 1)) 117,647.058823529 baud, or 102.124183007% of nominal.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi John, I figured you would know.  You know pretty much everything. 

 

I knew I wasn't being specific enough.  I'm using ATmega328P and Atmega1284P, both in DIP.  Both will go to 20 MHz above 4.5 V, but I might be running them at a slightly lower voltage, to make LED control a little easier.  I'm not sure yet, so I guess 14.7456 MHz could be a good choice too.  I think I will get a few of each, just to have on hand.  Thanks.

 

You're the best,

mark

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You know pretty much everything. 

Except how to make money......crying

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The best way to make money is to marry someone who makes a lot more than you.

 

It seems the error is 0 when UBRR = clk / 16 / BAUD - 1 is an integer.  Would it be possible to choose a BAUD = 100000 in the 16 MHz mega and in USB-serial FTDI and have it all work?  Can we choose any arbitrary BAUD rate we feel like, or are we constrained to the BAUD rates that are always used?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:

Can we choose any arbitrary BAUD rate we feel like, or are we constrained to the BAUD rates that are always used?

 

Like the Crazy Nasty--- Honey Badger (NSFW) the

AVR doesn't care.  It'll run at any speed you can set

in the UBRR register.  If you can do the same in the

other device, pick any speed you like.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is some program (or 2) somewhere that calculates the error rate for the chosen baud rate. The xmegas and the new tinys are a bit more flexible with their baud rate setting as they have a better prescaler.

 

I have never had to use non standard baud rates.

 

The best way to make money is to marry someone who makes a lot more than you.

hmmm 45 years too late.....

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avr-mike wrote:
Like the Crazy Nasty--- Honey Badger (NSFW) the AVR doesn't care. 

 

That guy really doesn't care.  He isn't afraid of anything.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
hmmm 45 years too late.....

Wow! 45 years.  Congratulations.  I'm coming up on 34 years with this wife.  The first one was a mistake from the beginning.  She made way less money than me, and she was way crazier than me.  This new one is much smarter than me.  I dont know why she puts up with my non-sense.

 

joeymorin wrote:
Switch to 2X mode, it will get you to within 2.13%.  Might work, might not, depending on the other side.

I thought about doing that, but I like the idea of using a weird frequency crystal.  Nothing else I am doing is dependent on the clock frequency, particularly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:

I thought about doing that, but I like the idea of using a weird frequency crystal.  Nothing else I am doing is dependent on the clock frequency, particularly.

 

I have in the past driven a micro from a VCO which was controlled by a PLL. One input to the PLL was from the micro itself, the other from an external signal. Like that I could synchronise the micro to an external signal, ensuring the micro's timing were exactly in time with the outside world. Many micro's will actually work all the way down to 0Hz as long as the clock speed changes smoothly.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How is the AS7265x clocked ? (Are you sure that it is running 115200 baud).

 

If one end is close to 100% correct, 3.5% error at the other end should be ok. 

 

(Perhaps try 125000 baud instead of 111111).

 

And like #3 running 2X will solve your problems.

 

But why not using I2C?  (I guess you also have that option.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:
Would it be possible to choose a BAUD = 100000 in the 16 MHz mega and in USB-serial FTDI and have it all work?
Possibly yes as the FTDI USB UART likely has a fractional baud rate generator (FBRG)

Unified memory AVR and XMEGA AVR have a FBRG.

FBRG in USB UART : Cypress, Exar, FTDI, likely Prolific PL2303, likely CH340

Microchip USB UART don't have FBRG; likewise with Silicon Labs CP2102N but its clock is 4 times greater (the error might be acceptable)

A UART might also have an auto-baud feature.

 

FTDI Knowledgebase - Aliasing Baud Rates

FTDI Knowledgebase - What Baud rates are achieveable?

Non-Standard Baud Rates in USB-Serial Bridge Co... | Cypress Developer Community

USB to UART Archives | Prolific USA | IC Design & Manufacturing

https://www.silabs.com/documents/public/data-sheets/cp2102n-datasheet.pdf (page 18)

Exar | Interface | USB UARTs

 

Edit: Exar

 

Edit2 :

Microchip USB UART don't have FBRG; likewise with Silicon Labs CP2102N but its clock is 4 times greater ...

likewise for USB PIC (up to 48MHz that's sync'd to USB SOF and a 16-bit baud rate register); USB PIC's UART also has auto-baud.

So, USB PIC instead of Microchip's USB UART.

PIC18F25K50 - Microcontrollers and Processors

A Minimal USB CDC ACM aka Virtual Serial Port

About Spare Time Labs - PIC18F4550 USB CDC ACM

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Mon. Feb 11, 2019 - 03:04 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:
I dont know why she puts up with my non-sense.

If the women don't find you handsome, they should at least find you handy. - Red Green

Quote by Red Green: “If the women don't find you handsome, they shou...”

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

"I'm a man.  But I can change.  If I have to.  I guess."

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
I have in the past driven a micro from a VCO ...
Some PIC have a NCO peripheral so can do some your method.

Another way is via a synchronizer if willing to lag "a bit"; for AVR, a sync might be implemented in XCL or CCL.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sparrow2 wrote:
How is the AS7265x clocked ? (Are you sure that it is running 115200 baud).

Interestingly enough the AS7265x has an onboard 16MHz Oscillator.  The data sheet claims the UART is Factory Set to 115.2k Baud

 

sparrow2 wrote:
But why not using I2C?  (I guess you also have that option.)

I am using I2C to set gain and integration time and to get the data from the detector, but UART looks straightforward for setting the calibration scalars.  It looks like I could do calibration from I2C too, but the data sheet is a little less clear on how to do that.  And since the detector is new to me, exploring it's various options is fun.

 

sparrow2 wrote:
And like #3 running 2X will solve your problems.

I tried talking over UART to an FTDI chip to USB to a PuTTY window at 115200 Baud, and could not do it with any of the 16 MHz megas I have.  I am sceptical that going to 2X and dropping the data rate by a third will work everywhere, but like you say, it may in some cases.  It is also only for Asynchronous mode.  I probably should have tried it, but changing out the crystal to get 0% error rate at all Baud rates appeals to me.  It is easy for me to change out the crystal on my boards, and it is a single line of code to change the F_CPU everywhere.  It seems especially bad if the AS7365x is also using a 16MHz oscillator and things could get way out of wack.

 

js wrote:
There is some program (or 2) somewhere that calculates the error rate for the chosen baud rate. The xmegas and the new tinys are a bit more flexible with their baud rate setting as they have a better prescaler.

The mega data sheet has an equation for calculating error rate

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:
It seems especially bad if the AS7365x is also using a 16MHz oscillator and things could get way out of wack.
Not crystal, but simple internal RC oscillator.  Has a range of 15.7-16.3 MHz, or about +/-1.9%.

 

As for the relationship between 16 MHz and 115.2kbps, don't make any assumptions.  The baud rate generator for the AS7265x may be very different from that used by the AVR.  The datasheet doesn't seem to go into any detail.

 

In any event, I'd be more concerned about the tolerance of the RC.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
In any event, I'd be more concerned about the tolerance of the RC.

Yeah, I am.  If nothing else, I will be able to talk to my microcontrollers with PuTTY at the higher Baud rate.  That's something good.  It also seems a lot of detectors and WiFi modules are all running at 11520, so I think changing crystals will let me play with my soldering iron and may have a positive result overall.  I will let people know what happens.

 

John, this is the error calculation in the mega data sheets:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
There is some program (or 2) somewhere that calculates the error rate for the chosen baud rate.

 

Sure are:

 

 

Attachment(s): 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sparrow2 wrote:
And like #3 running 2X will solve your problems.

Do I need to do something else, like recalculate UBBR? 

 

I turned on bit U2X1 in control register UCSR1A on the mega1284, and left everything else alone.  Everything else set at 112500 baud.  Still gibberish between the mega1284 and FTDI to PuTTY.  But better gibberish; ascii characters now instead of dense Japanese looking characters.  Just the wrong ones.

 

Digi-Key shipped some new crystals today, along with a couple of LEDs claiming to have peak output at 515 nm.  I have ordered 515 nm peak LEDs from 4 companies, and have gotten 518, two 520s amd a 524.   I already have 518.  515 seems to be a hard one to make.  All the manufacturers claim to have one, but they really dont.  For some people as long as it's green it's fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarkThomas wrote:
Do I need to do something else, like recalculate UBBR?
Yes.  The calculation should be with /8 instead of /16.

 

IMO it's better to use the tried and true setbaud.h:

#include <avr/io.h>
.
.
.
#define F_CPU 16000000
#define BAUD 115200
#define BAUD_TOL 3
#include <util/setbaud.h>
UBRR0 = UBRR_VALUE;
UCSR0A |= (USE_2X << U2X0);

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yup. that works.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Joey and Sparrow.  I wish I had listened to experience and saved myself $5 in crystals.  I needed to do a Digi-Key order anyway, so I am not counting the shipping.

 

2X does the job, and I am getting scalar values off the detector with UART.  Thanks so much!smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

THANKS AGAIN for the 2X solution!  I can read the scale factors and when I multiply them by the ADC raw data I get the calibrated values the sensor puts out, so now I can calibrate the thing and get some decent output values.  Yay!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Next time when you need 230400 you will use them.

 

Somewhere I have a hole box of 11.0592 MHz crystals from the "good" old 8051 time. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sparrow2 wrote:

Somewhere I have a hole box of 11.0592 MHz crystals from the "good" old 8051 time. 

 

You can never have too many useful crystal values...

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What no 3.579545 xtals?

 

Nice selection though!

 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Back in the day I think it was Maplin where I bought something like a mixed bag of 50 for something like £5. Something along these kind of lines:

 

https://www.ebay.co.uk/itm/Bag-m...