[En-Nut-Discussion] Proposal to change baudrate setting method using U2Xn
Henrik Maier
hmlists at focus-sw.com
Wed Feb 23 05:33:26 CET 2005
Hello fellow Developers,
I am currently working on the port to AT90CAN128. Usage of the CAN
controller requires the change of the MCU crystal to either 12MHz or
16MHz, otherwise standard CAN baud rates cannot be met.
These two clock speeds have the drawback that the accuracy of the 115
KBit speed is less than 3% if ones does not use the "Double the USART
Transmission Speed" feature of ATmega128 and AT90CAN128. This feature is
enabled by setting U2Xn to 1.
As this does not have any influence on the accuracy when using the
standard clock speed of 14.756MHz, I suggest to change the baud rate
configuration for all advanced AVR architectures in such a manner as to
set U2Xn = 1.
If this proposal finds general acceptance I am willing to commit the
code to the CVS.
As an example the code for setting the baud rate for debug0 would then
look like:
static int DebugIOCtl(NUTDEVICE * dev, int req, void *conf)
{
if(req == UART_SETSPEED) {
/*
* For hardware supporting doubling the USARTn transmission speed
* we do this as it gives better accuracy for 12MHz and 16MHz systems.
*/
#ifdef __AVR_ENHANCED__
u_short sv;
sv = (u_short) ((((2UL * NutGetCpuClock()) / (*((u_long *)conf)
* 8UL)) + 1UL) / 2UL) - 1;
sbi(UCSR0A, U2X0); /* double UART clock speed */
UBRR0L = (u_char) sv;
UBRR0H = (u_char) (sv >> 8);
#else
outb(UBRR, (u_char) ((((2UL * NutGetCpuClock()) / (*((u_long
*)conf) * 16UL)) + 1UL) / 2UL) - 1UL);
#endif
return 0;
}
return -1;
}
Regards
Henrik Maier
More information about the En-Nut-Discussion
mailing list