compiler issue with avrstudio 5?

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am a little confused now...

I normally written codes with atmega and uc3a chips and never had issues. But today when I for the first time used my previously written (but now changed to suit for Atxmega) USART printing libraries atxmega, I am seeing strange results...

Ok so I do this from my main code:

UsartSendString("Initialized...\r\n");

The function is defined as:

UsartSendString(char* str)
{
   while(str)
   {
      usart_putchar(&USARTE0, *str);
      str++;
   }
}

The result is that I see my "Initialized" printed on my hyperterminal, but added with that are lots of "no ascii symbols n bells" on my laptop. It seems to go round doing this 3 times and then stops....I have an LED ON OFF before and after printing this string and I can see the micro is doing fine..

I then wrote another printing routine that limits the printing by a certain length:

UsartSendString(char* str, int len)
{
   int i;
   for(i = 0; i < len; i++)
   {
      usart_putchar(&USARTE0, str[i]);
   }
}

Strangely enough, this one works fine and prints my message as expected with no additional bells n whistles on my hyperterminal...

So I am drawing the conclusion that the frist method somehow is not placing a null char at the end of my string so the while loop keeps going on printing garbage chars....

But why does this happen with atxmega and never happened for other platforms?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

meh how could I miss that one!
It should have been:

while(*str != '\0')
{

}

must have become lost in translation when converting the code from other micros...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

while(*str != '\0')
{

}


You might as well use:

while(*str)
{

}