CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

reading and writing 32-bit data in/from eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

reading and writing 32-bit data in/from eeprom
PostPosted: Wed Oct 13, 2010 4:40 am     Reply with quote

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: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 13, 2010 5:15 am     Reply with quote

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

View user's profile Send private message Visit poster's website

Re: reading and writing 32-bit data in/from eeprom
PostPosted: Wed Oct 13, 2010 5:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 13, 2010 6:19 am     Reply with quote

Sorry i mean to say 32-bits (4 bytes of data).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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