|
|
View previous topic :: View next topic |
Author |
Message |
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
writing int16 to flash |
Posted: Fri May 09, 2008 2:23 am |
|
|
good mowning,
I am working on a pic18f2520
I want to store some data in the flash memory.
using rs232, I communicate with my pc.
in my rs232 interrupt cycle, i capture the incoming values in an int16 array[64].
When the array is full, I set a flag, so in the main the value will be written using
Code: | write_program_memory(adress-64,array,128); |
adress being the adress to be written to
array a pointer to the complete array[64]
128 because int16 = 2 bytes, 64*2 = 128
now when i write for example to adress 192 to 256 values 100 to 164
And then read the memory i get this:
using function Code: | read_program_memory(adress,&val,2); |
adr : val
192 : 25856
193 : 101
194 : 26112
195 : 102
196 : 26368
197 : 103
...
this means that every 4 bytes my value is written.
but i don't understand why!
int16 is 2 bytes, I multiply my amount of in16s by 2 for the write function, and i use 2 bytes in my read function!
Someone has any idea?
Best regards,
Blob
[/code] |
|
|
Ttelmah Guest
|
|
Posted: Fri May 09, 2008 2:45 am |
|
|
The 'address', is a _byte_ location.
Your data, occupies _two_ bytes for every value.
If you imagine the data, and address in the memory, you should get:
Code: |
192 LSB first value
193 MSB first value
194 LSB second value
195 MSB second value
|
Now, it therefore makes no sense, to try to read a 16 bit value from the 'odd' addresses, since what then happens is you get half of one value, and half of the other stored the 'wrong way round' in your resulting number.
If you take '101' in decimal, and convert it to hex, you get '65'. The 16 bit hex word 6500, converted back to decimal, gives 25856, which is what you are seeing when you access address 192.
It looks as if your write address is wrong, and you are writing the 16bit values, to _odd_ addresses in the ROM. Then your 'retrieval' routine, needs to advance by _two_ bytes for each value to fetch, not by one.
Best Wishes |
|
|
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Fri May 09, 2008 3:01 am |
|
|
God said:
"Let Ttelmah be" ... and all was light!!!!
Thanks a lot!
Blob |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|