Been several years since I've posted on here after a break from any AVR/programming work.
So, after much searching - I can't seem to find quite the same problem in the forums, despite many threads surrounding string corruption. I've been working on a large project for several weeks, and in the last few days have run into one problem in particular I can't seem to get around.
I'm using strings in my application, written out onto a SPI TFT screen - where I'm displaying fixed text, variable text, changing colours etc all of which is working just fine. These strings are actually strings as pointers.
My string is declared in a .c file as:
and defined in a header file as:
extern char *str;
The string is then used as below, the functions display_goto_xy() and display_write_string() functions are my functions which deal with all the low level SPI routines to write data out to the display. Wherever I use the below, and whatever I place in "xxxxxxxxxxx" gets written out onto my display with no problems at all. Note I haven't written in any PROGMEM functionality yet, before I get bashed for RAM usage of fixed strings, it's on the todo list.
display_goto_xy(3, cursor_y); str = "xxxxxxxxxxx"; display_write_string(str, BLACK);
However, problems occur when I need to write a variable out, in particular when I need to convert an integer to string and then put this onto the display. So below, I'm clearing the previously displayed text by writing a string of spaces out onto the display (which works just fine in the above code without using itoa). Then I'm using itoa to convert a variable into a string, and push that out onto the display.
display_goto_setpoint(x,y); str = " "; display_write_string(str, BLACK); display_goto_setpoint(x,y); itoa(variable, str, 10); display_write_string(str, BLACK);
However, the problem I'm getting, is the displayed string seems to still contain old data. For example, if I write a value of 12 to the display (which displays fine), then 1023 (which displays fine), then 0, what I see on the display is 0023, despite having already cleared the previously displayed data.
The display is clearing fine, if I pause before writing the converted integer data, the screen is indeed displayed - so the routines writing to the display are working just fine.
What am I possibly doing wrong? When I write directly into the string, I don't have to 'clear' the contents of the array first, when using itoa(), do I have to empty out the array first?
Note I'm using using dtstrf() in place of itoa() where I need to convert float data to strings, and I get exactly the same issue as above...
dtostrf(float_data, 5, 1, str); // convert degrees C float into integer
Many thanks for your help in advance, I've gotten nothing but good replies in the past here.
EDIT - I should add, this is on a ATMega1284p @ 16MHz (large RAM requirement application for ADC data buffers before writing to SD), custom board. Entire application written in C, using avr-gcc Toolchain inside AS7.