Aaaand I figured it out. Some other code was disabling the TX pin as an output. 
I think the resulting failure of the last byte caused my terminal software, 
which was expecting UTF8, to mangle the result.


On Apr 27, 2013, at 01:52 , Rick Mann <[email protected]> wrote:

> A little more info: calling printf() twice seems to properly output the 
> string in the first call, and fails as described in the second. So, it's not 
> printf() per se that's failing, but something else.
> 
> On Apr 27, 2013, at 01:45 , Rick Mann <[email protected]> wrote:
> 
>> 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
> 
> 
> -- 
> Rick
> 
> 
> 
> 
> _______________________________________________
> AVR-chat mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/avr-chat


-- 
Rick




_______________________________________________
AVR-chat mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-chat

Reply via email to