View previous topic :: View next topic |
Author |
Message |
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Thu Jul 28, 2016 10:40 pm Post subject: M2561 Baud rate |
|
|
So....I've got the following in the start of my program
Code: | $regfile = "m2561def.dat"
$crystal = 16000000
$hwstack = 400
$swstack = 550
$framesize = 345
$Baud = 9600 |
Problem is, the baud rate of Com1 is actually 19200.
So I changed the baud rate to 19200 (to test with) and the actual baud rate of Com1 is 38400
4800 = 4800
57600 = 57600
I haven't checked all baud rate assignments however...
(BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Thu Jul 28, 2016 11:25 pm Post subject: |
|
|
Hi Ken,
looks like Bit 1 – U2Xn: Double the USART Transmission Speed in the UCSR0A is not set.
Try Adding
to your program to see if that helps, can't test it here no M2561. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Thu Jul 28, 2016 11:30 pm Post subject: |
|
|
Bug in the dat file then? |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Thu Jul 28, 2016 11:52 pm Post subject: |
|
|
KenHorse wrote: | Bug in the dat file then? |
BTW, I think you mean the bit *IS* set, so use Ucsr0a.u2x = 0 in my code.
(that seems to work) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jul 29, 2016 11:39 am Post subject: |
|
|
- do you use a boot loader?
- did you check if the speed is actual 16 MHz?
you can disable double speed calculation by remarking the u2x constant in the dat file.
if the compiler finds these constants, this bit is taken into account to calculate the best error free baud.
if it isnt found, it is not used. _________________ Mark |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Fri Jul 29, 2016 11:43 am Post subject: |
|
|
Hi Ken,
Reset the bit was my first thought too according this table. http://wormfood.net/avrbaudcalc.php
But compiling the code you provided didn't set the bit for me, so that made me changing to set the bit.
As mentioned before I don't have the mcu so testing was done in the simulator and there's it works always.
Btw the ide calculates the required register settings. Strange that you have a other out coming then me. Don't think the def file is the problem.
Have fun,
Evert _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Jul 29, 2016 12:55 pm Post subject: Re: M2561 Baud rate |
|
|
This code:
KenHorse wrote: |
Code: | $regfile = "m2561def.dat"
$crystal = 16000000
$hwstack = 400
$swstack = 550
$framesize = 345
$Baud = 9600 |
|
does set registers correctly, no false setting of U2X, as long if UCSR0A is untouched by other code.
It may be a flaw of the Bascom UART setup code, that only registers are set up, which need to be altered from default.
So as addressed already by Mark, if for example a bootloader alters registers UCSR0A, UCSR0C, they have to be (re-)set to proper state. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Fri Jul 29, 2016 3:59 pm Post subject: |
|
|
albertsm wrote: | - do you use a boot loader?
- did you check if the speed is actual 16 MHz?
you can disable double speed calculation by remarking the u2x constant in the dat file.
if the compiler finds these constants, this bit is taken into account to calculate the best error free baud.
if it isnt found, it is not used. |
Yes, I do use the "MCS" bootloader but I see nothing in that code setting the U2x bit. And also, yes, I am sure of the 16 mHz clock (if it wasn't, it seems to me that all baud rate settings would be off, no?)
I'm not quite sure why only the 9600 and 19200 baud rate selections seem to be affected by the U2X register setting but for my needs, setting Ucsr0a.u2x = 0 works for me |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Jul 29, 2016 5:08 pm Post subject: |
|
|
KenHorse wrote: | Yes, I do use the "MCS" bootloader but I see nothing in that code setting the U2x bit. |
The bootloader, i.e. baud rate code does this on its own.
If you compare baud rate tables in the ATM2561's data sheet, you'll notice at fosc = 16MHz an baud rate error of 0.2% for 19200 baud, independent of the use of U2X.
However at 57600 baud it's 2.1% at U2X=0, and -0.8% at U2X=1, so the compiler decides to use the lower error and thus sets U2X.
You won't see anything about it, beside if you disassemble the bootloader.
The clean exit for a BL would be to leave all registers in the previous condition. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Fri Jul 29, 2016 5:15 pm Post subject: |
|
|
MWS wrote: | KenHorse wrote: | Yes, I do use the "MCS" bootloader but I see nothing in that code setting the U2x bit. |
The bootloader, i.e. baud rate code does this on its own.
If you compare baud rate tables in the ATM2561's data sheet, you'll notice at fosc = 16MHz an baud rate error of 0.2% for 19200 baud, independent of the use of U2X.
However at 57600 baud it's 2.1% at U2X=0, and -0.8% at U2X=1, so the compiler decides to use the lower error and thus sets U2X.
You won't see anything about it, beside if you disassemble the bootloader.
The clean exit for a BL would be to leave all registers in the previous condition. |
Interesting that you mention that as I discovered this issue when porting mature code for an M128 to the 2561. The M128 code didn't exhibit this baud rate issue |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Jul 29, 2016 5:58 pm Post subject: |
|
|
KenHorse wrote: | Interesting that you mention that as I discovered this issue when porting mature code for an M128 to the 2561. The M128 code didn't exhibit this baud rate issue |
This shouldn't make a difference, beside that you've changed baud rates and/or crystal. |
|
Back to top |
|
|
KenHorse
Joined: 16 Jul 2004 Posts: 523
|
Posted: Fri Jul 29, 2016 6:26 pm Post subject: |
|
|
MWS wrote: | KenHorse wrote: | Interesting that you mention that as I discovered this issue when porting mature code for an M128 to the 2561. The M128 code didn't exhibit this baud rate issue |
This shouldn't make a difference, beside that you've changed baud rates and/or crystal. |
Nope, the EXACT SAME pc board - all I did was swap processors and port the code (change timer definitions, etc)
There is obviously something different about how the M128 code is compiled versus the M2561 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Fri Jul 29, 2016 6:45 pm Post subject: |
|
|
For 19200 baud U2X doesn't matter, whether set or cleared, only UBRR needs to be set right.
In case the compiler decided for the ATM128 to set U2X and fit UBRR to it, then a previously set U2X won't matter. |
|
Back to top |
|
|
|