EmbeddedRelated.com
Forums

flash memory(external)

Started by risha March 24, 2005
thanks for the help i was just trying something and it rather appears
very strange as i dont see any thing wrong in the code no errors or
any indication as to where i am going wrong there is junk value stored
in the varaible which just does not seem to go away what could be the
problem?

*****************
void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb)
{
   unsigned long ulvald;
   abb=2;
   ulvald=0;
   //fl_ad=(volatile unsigned long *)0x8020;
   ulvald= *(fl_ad);
   //return ucVal;
}

in the above prg the value of abb is shown as 2 but the value of
ulvald does not show 0 it shows a junk value in the debugger memeory
window
i initialized the value of the ulvald thinking that could initilize
the varaiable and then not have this junk value but the junk val just
stays put.

any suggestions help extended will be very helpful
regards,
risha wrote:
> ***************** > void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb) > { > unsigned long ulvald; > abb=2; > ulvald=0; > //fl_ad=(volatile unsigned long *)0x8020; > ulvald= *(fl_ad); > //return ucVal; > } > > in the above prg the value of abb is shown as 2 but the value of > ulvald does not show 0 it shows a junk value in the debugger memeory > window > i initialized the value of the ulvald thinking that could initilize > the varaiable and then not have this junk value but the junk val just > stays put. > > any suggestions help extended will be very helpful > regards,
IANALL, but ulvald is never used, and it is not volatile, and therefore the compiler likely performs an optimisation never setting its value. -- Michael N. Moran (h) 770 516 7918 5009 Old Field Ct. (c) 678 521 5460 Kennesaw, GA, USA 30144 http://mnmoran.org "So often times it happens, that we live our lives in chains and we never even know we have the key." The Eagles, "Already Gone" The Beatles were wrong: 1 & 1 & 1 is 1
" 
> IANALL, but ulvald is never used, and it is not volatile, > and therefore the compiler likely performs an optimisation > never setting its value. >
first i wanted to check that the value is in the debugger memory window should display correctly which is not happening first the varaible ucvald should be initialized to 0 which shows a junk value on execution of the stmt then the value at the particular location which is passed as a parameter should read the value at the location [(0x8020)which is actually 0x03 in my case]so the value in the memory window should have displayed 0x03 which shows junk value again. only when this works should i return the value ie ulvald from this function to the main program ofcourse changing the void return type of the function.So i need first the value displayed in the variable should be correct.Then can i proceed. any suggestions on this, regards risha
risha wrote:
> " >>IANALL, but ulvald is never used, and it is not volatile, >>and therefore the compiler likely performs an optimisation >>never setting its value. >> > > first i wanted to check that the value is in the debugger memory > window should display correctly which is not happening first the > varaible ucvald should be initialized to 0 which shows a junk value on > execution of the stmt then the value at the particular location which > is passed as a parameter should read the value at the location > [(0x8020)which is actually 0x03 in my case]so the value in the memory > window should have displayed 0x03 which shows junk value again.
If you want to prevent the compiler from eliminating useless expressions, then you will need to declare the variables as "volatile". Try this: void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb) { volatile unsigned long ulvald; // note volatile qualifier abb=2; // This will be eliminated since abb is a local copy. ulvald=0; // Now that uvald is volatile, this will show. ulvald= *(fl_ad); } -- Michael N. Moran (h) 770 516 7918 5009 Old Field Ct. (c) 678 521 5460 Kennesaw, GA, USA 30144 http://mnmoran.org "So often times it happens, that we live our lives in chains and we never even know we have the key." The Eagles, "Already Gone" The Beatles were wrong: 1 & 1 & 1 is 1
"Michael N. Moran" <mnmoran@bellsouth.net> wrote in message news:<x895e.30954$vL3.24650@bignews4.bellsouth.net>...
> risha wrote: > > " > >>IANALL, but ulvald is never used, and it is not volatile, > >>and therefore the compiler likely performs an optimisation > >>never setting its value. > >> > > > > first i wanted to check that the value is in the debugger memory > > window should display correctly which is not happening first the > > varaible ucvald should be initialized to 0 which shows a junk value on > > execution of the stmt then the value at the particular location which > > is passed as a parameter should read the value at the location > > [(0x8020)which is actually 0x03 in my case]so the value in the memory > > window should have displayed 0x03 which shows junk value again. > > If you want to prevent the compiler from eliminating > useless expressions, then you will need to declare the > variables as "volatile". Try this: > > void FlashReadM(volatile unsigned long *fl_ad,unsigned long abb) > { > volatile unsigned long ulvald; // note volatile qualifier > abb=2; // This will be eliminated since abb is a local copy. > ulvald=0; // Now that uvald is volatile, this will show. > ulvald= *(fl_ad); > }
thank you for your time and help. It is really great, now the ulvald value does get initialized to 0 initially but the next line i.e. ulvald=*(fl_ad);does not show the correct value 03, it shows junk value. It should have copied the value at fl_ad into the variable ulvald right? The value 03 value is not displayed at this location. NOTE: 0x8020 address is passed as a parameter(fl_ad) to the function FlashReadM and contains the value as 03(at this location 0x8020) regards,