There was a problem in the preprocessor, due to a bug in its calculation routine the result of "ChipMHz * 1000000" was getting multiplied by 10. This is what put everything else out by a factor of 10. When you moved the * 1000000, it changed the calculation slightly, and made the bug go away. I've now fixed the preprocessor, and the original USART code works properly with my Arduino at 57600 baud.
Using Gcbasic 0.9 18/2/2011
Could not get usart working in atmega32 and had a look to asm, UBRR values wasn't correct, then in usart.h all looked ok…
Finally i could get the correct valuesr:
The formula to calculate UBRR in usart.h, which is the same in datasheet:
UBRR_TEMP = ChipMHz * 1000000 / (16 * USART_BAUD_RATE) - 1
Gives wrong values, for example for 9600 bauds: UBRRL= 34, UBRRH =8 , when it should be UBRRL= 103, UBRRH =0
But if i use this one, i have correct values:
UBRR_TEMP = ChipMHz / (16 * USART_BAUD_RATE) * 1000000 - 1
________________________________________________________________________
Another cuestion:
I have a warning About the max clock speed for atmega32, in the dat file it's 8 MHz when it should be 16.
ATmega32L is 8MHz, but atmega32 is 16.
I think the same is for atmega16.
Best regads.
There was a problem in the preprocessor, due to a bug in its calculation routine the result of "ChipMHz * 1000000" was getting multiplied by 10. This is what put everything else out by a factor of 10. When you moved the * 1000000, it changed the calculation slightly, and made the bug go away. I've now fixed the preprocessor, and the original USART code works properly with my Arduino at 57600 baud.
I also dealt with the clock speed issue, that was a 5 minute job. Thanks for letting me know! All fixes are in the usual place, http://gcbasic.sourceforge.net/newfiles/update.zip
Sorry for my late reply… just to say again: Thanks!!
Arcachofo