View previous topic :: View next topic |
Author |
Message |
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
Posted: Mon Jan 31, 2022 3:31 am Post subject: baud rate of UART to 460800 in Atmega2560? |
|
|
Hello?
Is it possible to set the baud rate of UART to 460800 in Atmega2560?
When I set it to 230400, I confirmed that there was no problem.
I have searched a lot of resources to solve this problem, but to no avail.
Anyone please help.
thank you.
(BASCOM-AVR version : 2.0.8.5 ) _________________ I love freedom....
and....
I enjoy programming.... |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Mon Jan 31, 2022 8:52 am Post subject: |
|
|
With most common quartz 16MHz you get too big error 8,5% ...
but with quartz 18432000Hz (USART-friendly) with U2X enabled this baudrate can be easly achieved. UBBR will be = 4 and error = 0%
With quartz 11059200Hz also. UBRR will become 2 and error 0%
Last edited by EDC on Mon Jan 31, 2022 8:55 am; edited 1 time in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Jan 31, 2022 8:55 am Post subject: Re: baud rate of UART to 460800 in Atmega2560? |
|
|
BlackSky wrote: | I have searched a lot of resources to solve this problem, but to no avail. |
No avail to the data sheet?
Zero percent error with crystal 14.7456 MHz, UBBR = 1 & U2X = 0, alternatively UBBR = 3 & U2X = 1. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Feb 01, 2022 8:32 pm Post subject: |
|
|
i wonder : did you actual try it?
And is there some problem?
when using config comx = baud_you_want , the proper value should be calculated. when the uart has a double speed flag, it will be used too when it will result in a lower baud error. but like mentioned, selecting the proper xtal is key.
now where you can get problems : in the PC/device driver. i noticed that built in COM port does not accept that same speeds as some virtual (USB) drivers.
But these are higher speeds. _________________ Mark |
|
Back to top |
|
|
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
Posted: Wed Feb 02, 2022 1:13 am Post subject: |
|
|
Thank you for your advice.
Since I am testing with an Arduino Mega 2560 board,
I cannot replace the crystal,
so I change the fuse bit to the internal RC OSC and try $crystal = 11059200 and 14745600, but the transmission data is not normal. _________________ I love freedom....
and....
I enjoy programming.... |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Feb 02, 2022 1:35 am Post subject: |
|
|
Directive $crystal is not a setting for processor clock.
This is the info for Bascom and should match real uC clock speed.
That info is needed for proper calculating UBRR for UART and delays like Wait, Waitms etc.
If you have internal osc enabled, 8MHz for example, and set $crystal = 11059200 then you cheat Bascom and yourself. Nothing depend on time will be working like it should.
If you dont know how to change the quartz then you should choose another baud.
Maximum % of error should not exceed 2,5% but maybe your 3,5% at baud 230400 was somehow working.
But baud 460800 have 8,5% in any of two options of U2X.
Baud U2X=0 U2X=1
230400 8,5% -3,5% @16MHz
460800 8,5% 8,5% @16MHz
250000 0% 0% @16MHz
500000 0% 0% @16MHz
Better choose 250k or 500k with zero percentage error at 16MHz. |
|
Back to top |
|
|
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
Posted: Wed Feb 02, 2022 2:15 am Post subject: |
|
|
Thanks for the advice.
The Arduino Mega 2560 board has a very small crystal, so it was difficult to replace it.
However, as you said, I understand that errors occur depending on the crystal.
I'll make an Atmega2560 board that I can test on and try again by applying the crystal to 11.0592 or 14.7456.
thank you. _________________ I love freedom....
and....
I enjoy programming.... |
|
Back to top |
|
|
BlackSky
Joined: 01 Jan 2008 Posts: 21 Location: South Korea
|
Posted: Wed Feb 02, 2022 2:17 am Post subject: |
|
|
Thank you to everyone who has kindly provided advice. _________________ I love freedom....
and....
I enjoy programming.... |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Thu Feb 03, 2022 7:51 pm Post subject: |
|
|
You can also use "OSCCAL" to adjust the internal oscillator to a functional frequency within limits.
Oscilloscope would help (or a subprogram with known counts).
Regards
Hubert |
|
Back to top |
|
|
|