|
|
View previous topic :: View next topic |
Author |
Message |
hayee
Joined: 05 Sep 2007 Posts: 252
|
reading and writing 32-bit data in/from eeprom |
Posted: Wed Oct 13, 2010 4:40 am |
|
|
Hi,
I am reading and writing 16-bit data in eeprom using macros like following
Code: |
#define mReadWord(addr) make16(read_eeprom(addr+1),read_eeprom(addr)) //macros for read and write on
#define mWriteWord(addr,data) write_eeprom(addr,make8(data,0));write_eeprom((addr+1),make8(data,1));}//eeprom
|
Now I want to write 3-bit data in eeprom, can I do something like that
Code: |
#define mReadLong(addr) make32(read_eeprom(addr+3),read_eeprom(addr+2),read_eeprom(addr+1),read_eeprom(addr))
#define mWriteLong(addr,data) {write_eeprom(addr,make8(data,0));write_eeprom((addr+1),make8(data,1));write_eeprom((addr+2),make8(data,2));write_eeprom((addr+3),make8(data,3));} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9250 Location: Greensville,Ontario
|
|
Posted: Wed Oct 13, 2010 5:15 am |
|
|
something is lost in posting of your question
3 bit data can easily be stored as a single byte using a simple mask to hide the unused bits.
now if you meant 24 bit data ( 3 BYTES), then simply store them as a 32 bit word,again you could mask off the unused bits of the data. |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
Re: reading and writing 32-bit data in/from eeprom |
Posted: Wed Oct 13, 2010 5:22 am |
|
|
hayee wrote: | Hi,
i am reading and writing 16-bit data in eeprom using macros like following
#define mReadWord(addr) make16(read_eeprom(addr+1),read_eeprom(addr)) //macros for read and write on
#define mWriteWord(addr,data) write_eeprom(addr,make8(data,0));write_eeprom((addr+1),make8(data,1));}//eeprom
now i want to write 3-bit data in eeprom, can i do something like that
#define mReadLong(addr) make32(read_eeprom(addr+3),read_eeprom(addr+2),read_eeprom(addr+1),read_eeprom(addr))
#define mWriteLong(addr,data) {write_eeprom(addr,make8(data,0));write_eeprom((addr+1),make8(data,1));write_eeprom((addr+2),make8(data,2));write_eeprom((addr+3),make8(data,3));} |
Yes you can. If you are really needing only three bytes (24 bit) then only store that many. There's no reason to waste space if you will never use it. You can just pass 0 for the missing fourth byte to make32.
But, if there is any chance of needing more than 24 bits then you should certainly save and load all 4 bytes. |
|
|
hayee
Joined: 05 Sep 2007 Posts: 252
|
|
Posted: Wed Oct 13, 2010 6:19 am |
|
|
Sorry i mean to say 32-bits (4 bytes of data). |
|
|
|
|
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
|