Frage

I am helping a friend get a graphics LCD working on his AVR, a few months ago all was working without issue, it has been untouched since then. The chip has now been swapped out from an ATMega32 to an ATMega164P. Essentially the same chip with more flash, since this change a lot of the code has stopped working.

We have narrowed where the error is occuring, but are unable to rectify it. It is where we pass in a pointer to a const char string, and attempt to print that string, however for some reason the stack(heap, something else?) gets corrupted and the pointer contains all zeros. Does anyone have any ideas how this could occur? We have -O1 level optimisations enabled which are required for correct timing, we have switched to winAVR compiler as well with no changes. We also do not have access to a debugger, and only have limited 'print' style debugging.

Here is the section of code that is causing issues:

//in the header file that is included
int SGCTEXTStringF(int column, int row, int font, int colour, const char* text);

//Call the function
SGCTEXTStringF(0, 0, 0x10, SGCColour(255,255,255), "text");

//Function
int SGCTEXTStringF(int column, int row, int font, int colour, const char* text){

unsigned char bytes[23]={0};

//...Code to communicate with LCD and set up a 'print string'

if(text[0] == 0) {
    bytes[6] = 'a'; 
    bytes[7] = 't';
    bytes[8] = 'e';
    bytes[9] = 's';
    bytes[10] = 't';
}

//..more code to finish sending the array
}

Now the display prints 'atest' when the code is run, this is showing that the const char array is being some how zero'd? I have also tried the following lines which also all print 'atest'

if(text[1] == 0)   //prints 'atest'
if(*text== 0)      //prints 'atest'
if(text != 0)      //prints 'atest'

This shows that it gets a valid pointer, but it appears to point to all zeros.

We also tried changing the call to the method to:

const char * string = "test";
SGCTEXTStringF(0, 0, 0x10, SGCColour(255,255,255), string);

This code was known to be working a few months ago, we even have a video of it running, now every single function in the program exhibits the same issue, char arrays being passed (on the stack?) don't seem to work and get cleared to 0s.

I can arrange to host a copy of the complete source code if anyone is interested. Any help or pointers at all are appreciated!

War es hilfreich?

Lösung

The ATMega164P is not the replacement for the ATMega32 but for the ATMega16. For the ATMega32 you would need the ATMega324P. If you are using the memory map for the ATMega32 (which has double EEPROM, SRAM and flash), your string may have landed in memory which simply does not exist. For porting issues you may look at the porting guide from Atmel.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top