Rafael Ruiz

Problems with arguments receiving in functions.

Discussion created by Rafael Ruiz on Nov 7, 2006
Latest reply on Nov 21, 2007 by Alessandro Dionisi
Hi to all, im using codewarrior for an embedded system an i was doing some write/read memory routines, everything was working fine but suddenly the compiler turns strange with the parameters receiving, here is an actual code ill explain what happens after it:

This is the calling to the function on the code:

writeByteToEeprom ('@', 0x1600, 0); //just write anything for testing purposes.

This is the actual function:

short writeByteToEeprom (unsigned char value, int address, short page)
{
unsigned char *Pointer = NULL;
short couldWrite = 1;

if (address >= 0x1600 && address = 0x17FF) //Validating the address
{
//MCGInit(); //Configure the unit's clock to 40 mhz and the bus to 20 mhz.
if (page > 1 || page 0)
page = 0;
FCNFG_EPGSEL = page;
FOPT_EPGMOD = 1; //8 byte sector
FCDIV_PRDIV8 = 1; // divide the bus frequency / 8.
FCDIV_DIV = 12; //Set fFCLK to 192.3 khz (necessary for the flash and EEPROM programming).
while (FCDIV_DIVLD == 0)
; //Ensure that the divisor has loaded correctly.
FSTAT_FACCERR = 0; //Ensure that this flag is cleared.
Pointer = (unsigned char *)address;
*Pointer = value;
FCMD = 0x20; //Byte program command code.
FSTAT_FCBEF = 1; //Launch the command
while ((FSTAT & FSTAT_FCCF_MASK) == 0) //Wait until the write is done, and stop if an error occurs.
{
if (FSTAT_FACCERR == 1)
{
couldWrite = 0;
break;
}
__RESET_WATCHDOG();
}
}
else
couldWrite = -1;

return couldWrite;
}

When debuggin (or running) the program, the function receives the argument variables as listed:

value = 1 (instead of 64, the @).
address = 124 (instead of 5632 (0x1600)).
page = 16384 (instead of 0).

I attach a screenshot of the debugging window. Im using a dbm.

The strange thing is when it calls the function it receives the parameters ok but when the pointer of the line goes into the brackets {} the parameters values change to the values above. This is the first time im working on an embedded system so if you have som advises they are welcome. Also i attach an image where you can see the change from the correct values (when the debugger pointer is at the very first line of the function) and the strange values (when the debugger pointer change to the next line of the function).

Thank you in advance!

Message Edited by Saga on 2006-11-0701:53 PM

Outcomes