Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Problem regarding to 24c16 EEPROM

Status
Not open for further replies.

Sudhp

Member level 4
Joined
Oct 11, 2013
Messages
69
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Location
India
Activity points
528
hi experts....
I m working on a project which have a 24c16 EEPROM....
My programming for this is given-

Code:
void save()					
{start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
send_byte(arm_hr);aknowledge();
send_byte(arm_min);aknowledge();
send_byte(dis_hr);aknowledge();
send_byte(dis_min);aknowledge();
send_byte(htr_time);aknowledge();
send_byte(ent_time);aknowledge();
send_byte(ext_time);aknowledge();
send_byte(zone_key[1]);aknowledge();
send_byte(zone_key[2]);aknowledge();	
send_byte(zone_key[3]);aknowledge();	
send_byte(zone_key[4]);aknowledge();
send_byte(zone_key[5]);aknowledge();
send_byte(zone_key[6]);aknowledge();
send_byte(zone_key[7]);aknowledge();
send_byte(zone_key[8]);aknowledge();
stop();
}



void Read()
{start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
start();
send_byte(0xA1);
aknowledge();
arm_hr=read_byte();aknowledge();
arm_min=read_byte();aknowledge();
dis_hr=read_byte();aknowledge();
dis_min=read_byte();aknowledge();
htr_time=read_byte();aknowledge();
ent_time=read_byte();aknowledge();
ext_time=read_byte();aknowledge();
zone_key[1]=read_byte();aknowledge();
zone_key[2]=read_byte();aknowledge();	
zone_key[3]=read_byte();aknowledge();	
zone_key[4]=read_byte();aknowledge();
zone_key[5]=read_byte();aknowledge();
zone_key[6]=read_byte();aknowledge();
zone_key[7]=read_byte();aknowledge();
zone_key[8]=read_byte();aknowledge();
stop();
}



The size of EEPROM is 2 k byte....
But when I save 4 more variables ......it is not storing them....
why is this happening....?
Is the space of EEPROM is completely full......?
if not then why it is not storing further variables.....

My way of storing the variables is right or something else????/
 
Last edited by a moderator:

read datasheet of 24c16 24c16 is 16 byte page write mode .
 

24c16 is 16 byte page write mode
The shown write code is keeping the 16 Byte range. Probably the data is read before the write operation has finished, can't be see from the incomplete code snippets.

Usually we would check the acknowledge bit after send_byte().
 

the complete programming for eeprom is as-
HTML:
void aknowledge()	  
{ scl=1;_nop_();_nop_();scl=0;} 

void start()		
{sda=1;	scl=1;	_nop_();_nop_();sda=0;scl=0;}

void stop()			
{sda=0;	scl=1;	_nop_();_nop_();sda=1;scl=0;}

unsigned char read_byte()
{unsigned char reead;	
 unsigned int i;
 	sda=1;
	reead=0;
	for(i=0;i<8;i++)
	{
	reead=reead<<1;
	scl=1;
	_nop_();
	_nop_();
		if(sda==1)
		reead++;
		scl=0;
		}
		sda=0;
		return reead;}

void send_byte(unsigned char value)
{ 	unsigned int i;
    unsigned char send;
	send=value;
	for(i=0;i<8;i++)
	{sda=send/128;
	send=send<<1;
	scl=1;
	_nop_();
	_nop_();
	scl=0;}
	ack=sda;
	sda=0;}

void save()					
{start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
send_byte(arm_hr);aknowledge();
send_byte(arm_min);aknowledge();
send_byte(dis_hr);aknowledge();
send_byte(dis_min);aknowledge();
send_byte(htr_time);aknowledge();
send_byte(ent_time);aknowledge();
send_byte(ext_time);aknowledge();
send_byte(user_key[0]);aknowledge();
send_byte(user_key[1]);aknowledge();
send_byte(user_key[2]);aknowledge();
send_byte(user_key[3]);aknowledge();
send_byte(zone_key[1]);aknowledge();
send_byte(zone_key[2]);aknowledge();	
send_byte(zone_key[3]);aknowledge();	
send_byte(zone_key[4]);aknowledge();
send_byte(zone_key[5]);aknowledge();
send_byte(zone_key[6]);aknowledge();
send_byte(zone_key[7]);aknowledge();
send_byte(zone_key[8]);aknowledge();
stop();
if(key[0]=='9' && key[1]=='5'&& key[2]=='6' && key[3]=='7')
{send_command_lcd(0x80,"Settting default  \0");
send_command_lcd(0xc0," Please wait...    \0");
delay();delay();delay();delay();delay();
main_full();
}
settings();
}



void Read()
{start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
start();
send_byte(0xA1);
aknowledge();
arm_hr=read_byte();aknowledge();
arm_min=read_byte();aknowledge();
dis_hr=read_byte();aknowledge();
dis_min=read_byte();aknowledge();
htr_time=read_byte();aknowledge();
ent_time=read_byte();aknowledge();
ext_time=read_byte();aknowledge();
user_key[0]=read_byte();aknowledge();
user_key[1]=read_byte();aknowledge();
user_key[2]=read_byte();aknowledge();
user_key[3]=read_byte();aknowledge();
zone_key[1]=read_byte();aknowledge();
zone_key[2]=read_byte();aknowledge();	
zone_key[3]=read_byte();aknowledge();	
zone_key[4]=read_byte();aknowledge();
zone_key[5]=read_byte();aknowledge();
zone_key[6]=read_byte();aknowledge();
zone_key[7]=read_byte();aknowledge();
zone_key[8]=read_byte();aknowledge();
stop();
}


It is not working for last 3 variable....i.e
zone_key[6],zone_key[7] nd zone_key[8]....

plz somebody help me....
 

It is not working for last 3 variable....i.e
Yes, as expectable according to the datasheet. You have to stop the page write after 16 Bytes. Then poll for ready, then start a new write sequence for the remaining data.
 
  • Like
Reactions: Sudhp

    Sudhp

    Points: 2
    Helpful Answer Positive Rating
ok......thn wat will be the next addressess...
either i hav to change it or it will be same..
 

After writing 16 Bytes, the second page write would start at byte address 16 instead of 0. If timing isn't critical, you can wait for the maximum write time (5 or 10 ms depending on the device type) without polling for write success.
 

IDeally, you should write your code so that it checks if a 16byte boundary will be crossed, and have it insert a cycle to set the address pointer properly at the right point, or else simply not allow 16 byte buffers to be crossed. Many of the eproms have an auto-increment address register feature which can be turned on or off if that makes things easier for you, though you will have to treat every write/read as a cycle which specifies the target address up front.
 

ftsolution....as u mentioned
eproms have an auto-increment address register feature


Can u suggest me the name of these type of eeprom having same memory space and
for that I use the above mentioned program.....
 

I mis-spoke about being able to turn off the auto-increment feature explicitly - basically if you want to be able to do random access reads in the eprom, you'll have to start a write cycle with the address you want to read specified, and then (re) issue a start condition after the eprom accepts the address - this terminates the write cycle without writing anything but resets the address pointer to the specified address. You then issue a read command and the eprom will emit the data at the specified address, after which you issue a "stop".

IF you want to access a page at a time (16 bytes, on aligned 16 byte address boundaries), you can do that with either read or writes by simply having the master acknowledge the data byte from the eprom instead of issuing a stop, and it will continue to send you the next sequential data byte within the page. If you attempt either to write or read past a page address boundary, it will simply wrap back around to the start of the same page again. Note that you must also allow time for write processing to complete before you try to re-access data within that same page.

Most all of these24LCxx eproms work the same way - though some are capable of slightly higher speeds of transfer or write time, you should write your code to work as generically as possible.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top