Skip to main content
added 962 characters in body
Source Link
Oldfart
  • 14.7k
  • 2
  • 18
  • 42

Use:

while (*str) sendChar(*str++); 

You might want to add carriage returns if the string has line feeds:

while (*str) { if (*str==0x0A) sendChar(0x0d); sendChar(*str++); } 

Your latest debug data shows what I have been expecting all along: your string array does not get initialized. Although this is not strictly correct according to the C/C++-code, it does not surprise me. When working with micro controllers there are often limitations to what is supported by the compiler. I suspect your compiler does not support initialisation of variables on function call.

I suggested some time ago to make the string global. The reason is that most MCUs have code in the crt0.s to copy values from ROM to RAM on startup for initialized variables. The copy has to be done because you specified the string as 'changeable' thus it must reside in RAM. If you make the value

const char str[100] = ".."; 

The string is likely to be mapped to the ROM area as there is never need to change it. Check your compiler manual which should have a section on how variables are mapped depending on how you define them.

Use:

while (*str) sendChar(*str++); 

You might want to add carriage returns if the string has line feeds:

while (*str) { if (*str==0x0A) sendChar(0x0d); sendChar(*str++); } 

Use:

while (*str) sendChar(*str++); 

You might want to add carriage returns if the string has line feeds:

while (*str) { if (*str==0x0A) sendChar(0x0d); sendChar(*str++); } 

Your latest debug data shows what I have been expecting all along: your string array does not get initialized. Although this is not strictly correct according to the C/C++-code, it does not surprise me. When working with micro controllers there are often limitations to what is supported by the compiler. I suspect your compiler does not support initialisation of variables on function call.

I suggested some time ago to make the string global. The reason is that most MCUs have code in the crt0.s to copy values from ROM to RAM on startup for initialized variables. The copy has to be done because you specified the string as 'changeable' thus it must reside in RAM. If you make the value

const char str[100] = ".."; 

The string is likely to be mapped to the ROM area as there is never need to change it. Check your compiler manual which should have a section on how variables are mapped depending on how you define them.

Source Link
Oldfart
  • 14.7k
  • 2
  • 18
  • 42

Use:

while (*str) sendChar(*str++); 

You might want to add carriage returns if the string has line feeds:

while (*str) { if (*str==0x0A) sendChar(0x0d); sendChar(*str++); }