I'll try to quote to make it clearly what I'm answering to:
Me:
>>>The problem lies, according to me, that when you call the macro inside
>>>the function, the baudrate variable is a 16bit variable so the value 65535
>>>is 0xffff and the value 65536 is 0x0000 (should be 0x10000 but it's truncated)
Axel:
>As for uint16_t br in HIF_UART_INIT: br is not the baudrate, br is the
>value for the UBRRxH and UBRRxL register. According to the data sheet
>the value for UBRR (br) has a range of 0 ... 4095 - the higher values it
>gets for lower baud rates.
Me:
I meant the 'baudrate value', not the 'encoded value'.
In the code I see:
#define ENCODE_BAUDRATE(br) ((F_CPU)/((br)*16l)-1)
inline void HIF_UART_INIT(uint16_t baudrate)
{
uint16_t br;
br = ENCODE_BAUDRATE(baudrate);
/* Set baud rate */
if ( br & 0x8000 )
{
HIF_UART_STATUS = _BV(U2X0); //Enable 2x speed
br &= ~0x8000;
}
UBRR1H = (uint8_t)(br>>8);
UBRR1L = (uint8_t) br;
....
}
The second line is the interesting one, the definition on the HIF_UART_INIT() function uses an uint16_t variable type.
Which means that the ENCODE_BAUDRATE(br) macro is using a 16bit variable as an input.
When I call the function with the value 0xfffF, HIF_UART_INIT(0xffff), I'm actually calling the ENCODE_BAUDRATE macro as: ENCODE_BAUDRATE(0xFFFF)
But when I call the function with the value 0x10000, HIF_UART_INIT(0x10000), I'm actually calling the ENCODE_BAUDRATE macro as: ENCODE_BAUDRATE(0x0000)
Am I wrong here?
(and yes, the br variable inside the HIF_UART_INIT() function is the output of the ENCODE_BAUDRATE macre and should overflow under any circumstance)
>I just tried 250kbps/16MHz on Radiofaro - together with a python terminal (sterm.py) it worked.
>However this was with the current Mercurial version, but with the last release 0.4.2, I failed the
>same way like you. (250kbs fit better to the 16MHz).
Could you give me a link to the mercurial version?
I might find the differences that are causing the serial communication error.