This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

simple code not always working

Hi
I have a function InitRAM
This way it works:

unsigned char Flash_Data[512];
unsigned int AnalogMaxValues[8];
#define AnalogMaxValues_start 129   //byte number of AnalogMaxValues in flash block

void InitRAM()
{
  unsigned char i;
  unsigned int index,index2,a,b;
  memcpy(&Flash_Data, ConfigStartAddress, sizeof(Flash_Data)) ;

  //save Analog related values to SRAM
  for(i=0;i<8;i++)
  {
        index =AnalogMaxValues_start+2*i;
        index2=AnalogMaxValues_start+2*i+1; //index+1;
        a= Flash_Data[index];
        b= Flash_Data[index2];
        AnalogMaxValues[i]     = a+ (b<<8);  //this is a 2 byte variable
  }

}


And AnalogMaxValues[i] have correct values
But the code below should do the same, while it's not working

unsigned char Flash_Data[512];
unsigned int AnalogMaxValues[8];
#define AnalogMaxValues_start 129   //byte number of AnalogMaxValues in flash block

void InitRAM()
{
  unsigned char i;
  unsigned int index,index2,a,b;
  memcpy(&Flash_Data, ConfigStartAddress, sizeof(Flash_Data)) ;

  //save Analog related values to SRAM
  for(i=0;i<8;i++)
  {
        index =AnalogMaxValues_start+2*i;
        index2=AnalogMaxValues_start+2*i+1; //index+1;
        AnalogMaxValues[i] = (int)Flash_Data[index]+ ((int)Flash_Data[index2]<<8);
  }

}


and Flash_Data[index] and Flash_Data[index2] seem to be the same while they are not
I'm using Keil uVision
Do you think I have a problem in the second code?

Parents Reply Children