you need to store those 32 bits in successive loaction either from MSB to LSB or from LSB to MSB and retrieve back from the same location in same format how you written...
but how to convert it into 4 portions each 8bits then how to reconvert it to one 32bits number wfter reading
- - - Updated - - -
its great i got the conversion concept 32bits number to 4 parts each 8bits and stored it but on reading the eeprom i will get 8bits portion then 4portions each 8bits need to be converted back into 32bits number how to combine it....thanks too much, Easyrider83
This method is certainly fine, but I usually prefer this one:
Code C - [expand]
1
2
3
4
EEWrite32(uint32 address,uint32 value){uint8* valarray =(uint8*)(&value);for(int i =0; i <4;++i) EEWrite8(address+i, valarray[i]);}
The advantages: it is more compact, and it works the same way, on big endian and little endian machines.
I like it because it takes data as it is and where it is. It is clean beacuse it does not feed a 32-bit parameter
((value & 0xFF000000) >> 24) is anyway a 32-bit value from the processor point of view, with 24 leading
0s) into a function that expects a 8-bit parameter.
I have never tested which one is faster, but since the EEPROM write is incredibly slow, I guess there is not that
much difference.
But anyway, that's more of a matter of taste.
Two things:
- I have never used a 8 bit microcontroller;
- I have used the above source myriads of times.
Ok, I don't pretend I have that much experience in microcontroller programming.
However, if I may comment what you said, you would be a lot more convincing by
giving us a concrete overview of what may happen by using the code I was suggesting.
Do you have any concrete environment / processor configuration where this would not
work?
And never compare C code. Always compare only assembly output.
Well, you have your programming methods, I have mine. You compare assembly?
I compare the results and the speed. I just compared the speed, and the array
method is faster. And in all the environments I used the array method, there was no error.