In my ATmega* projects, I often do something like this:
int
uart_putchar(char inC, FILE* inStream)
{
while (!(UCSR1A & (1 << UDRE1)))
{
}
UDR1 = inC;
return 0;
}
int
main()
{
static FILE sStdOut;
sStdOut.put = uart_putchar;
sStdOut.get = __null;
sStdOut.flags = 0x0002;
sStdOut.udata = 0;
stdout = &sStdOut;
}
So, in my XMEGA project, I did this:
inline
void
debugPutByte(uint8_t inByte)
{
while ((USARTE0.STATUS & USART_DREIF_bm) == 0);
USARTE0.DATA = inByte;
}
static
int
stdioPutChar(char inC, FILE* inStream)
{
debugPutByte(inC);
return 0;
}
int
main()
{
static FILE sStdOut;
sStdOut.put = stdioPutChar;
// sStdOut.get = __null;
sStdOut.flags = 0x0002;
sStdOut.udata = 0;
stdout = &sStdOut;
printf("Hello world");
}
A couple things went wrong. One minor one was the line assigning __null
produces this error:
main.c:132:16: error: expected expression before '__null'
But I figured it's nulled out as a static, anyway, so I comment it out.
The real problem is when I call printf, the output I get always mangles the
last 3 characters in the string:
> Hello woü
A "raw" print of a string using debugPutByte() above seems to work fine.
Any ideas?
Thanks,
--
Rick
_______________________________________________
AVR-chat mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-chat