AnsweredAssumed Answered

failure to return from function?

Question asked by ROB LUND on Nov 9, 2010
Latest reply on Nov 10, 2010 by ROB LUND

Sorry for the lack of details in that subject line. I'm working with the MC9S08QG8 and have written a function to access external EEPROM and print to UART the results.  This function uses a local array of 14 bytes.  I have a local pointer to this array which I use to do the heavy lifting.  See below:



void RawMemory(void){  word addr = 0;  byte eeprom[PARAMETERS] = {0};      // EEPROM memory array  byte* eeprom_ptr = eeprom;          // pointer to array  NewLineChars();  SendString("Memory:"); NewLineChars();  do  {    i2c_error = I2CRandomRead(EEPROM_ADDR,addr,eeprom_ptr);    if (i2c_error)    {      i2c_clk_dly = I2C_CLK_DLY2;   // try slower I2C clocking speed and retry      addr = 0;      eeprom_ptr = eeprom;    // reset RAM array pointer      i2c_error = 0;    // reset flag    }    else if (*eeprom_ptr == BLANK_BYTE)    {      NewLineChars();      break;  // stop reporting once blank spot found    }    else    {      SendAscByte(*eeprom_ptr);      // report EEPROM value      TxChar(SPACE);    }    if (eeprom_ptr == eeprom + PARAMETERS)    {      CursorString();   // command line      eeprom_ptr = eeprom;    // reset RAM array pointer    }    else eeprom_ptr++;  } while (++addr < EEPROM_BUFF); // end while loop} // end RawMemory()



This function works as it should.  However, when returning from the function, the program "runs off into the weeds."  I've tried upping my stack pointer in the .prm file, as high as the compiler would let me.  No effect.


Assuming it was the size of the local array, I even tried a different approach with a single byte variable for 'eeprom'.  Still the same problem.


RAM problems have always been a bit mysterious to me in terms of troubleshooting.  Any recommendations?  Thanks!