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.

interface eeprom AT24C32 with 89S52

Status
Not open for further replies.

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
640
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,298
Activity points
6,922
HI all,
i need a small help from you all....
i am trying to interface AT24C32 eeprom with 89S52.
my problem is it works perfectly with proteus stimultion but when i tried to built the circuit it give me an error...
code...
Code:
#include<reg51.h>
#include<stdio.h>
#include<intrins.h>   //For using [_nop_()]

sbit sda=P1^7;
sbit scl=P1^6;

sbit buz=P3^7;

bit ack;
void save();
void read();
void msdelay(unsigned int value)  ;

unsigned char reead,write,write2,i,j;
unsigned int temp;
unsigned char userid[7]={"444444"};
unsigned char chanuser[7]={"000000"};

void aknowledge()	  //acknowledge condition
{
	scl=1;
	_nop_();
	_nop_();
	scl=0;
} 
void start()		//start condition
{
	sda=1;
	scl=1;
	_nop_();         //No operation
	_nop_();
	sda=0;
	scl=0;
}
void stop()			//stop condition
{
	sda=0;
	scl=1;
	_nop_();
	_nop_(); 
	sda=1;
	scl=0;
}
void send_byte(unsigned char value)	//send byte serially
{ 
	unsigned int i;
	unsigned char send;
	send=value;
	for(i=0;i<8;i++)
	{
		sda=send/128;		//extracting MSB
		send=send<<1;		//shiftng left
		scl=1;
		_nop_();
		_nop_();
		scl=0;
	}
   ack=sda;		//reading acknowledge
   sda=0;
}
unsigned char read_byte()	//reading from EEPROM serially
{
	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;	//Returns 8 bit data here
}		

void save()		//save in EEPROM
{
    start();
	send_byte(0xA0);	//device address
	aknowledge();
	send_byte(0x00);	//word address, Page Numbers
	aknowledge();
	send_byte(userid[0]);   
	aknowledge();
	send_byte(userid[1]);      
	aknowledge();
	send_byte(userid[2]);      
	aknowledge();
	send_byte(userid[3]);      
	aknowledge();
	send_byte(userid[4]);      	//send data
	aknowledge();
	send_byte(userid[5]);  	//send data
	aknowledge();
	stop();
}

void Read()
{
	start();
	send_byte(0xA0);
	aknowledge();
	send_byte(0x00);
	aknowledge();
	start();
	send_byte(0xA1);		 //device address
	aknowledge();
	chanuser[0]=read_byte();
	aknowledge();
	chanuser[1]=read_byte();
	aknowledge();
	chanuser[2]=read_byte();
	aknowledge();
	chanuser[3]=read_byte();
	aknowledge();
	chanuser[4]=read_byte();
	aknowledge();
	chanuser[5]=read_byte();
	aknowledge();
	stop();
}
	
void main()
{
  save();
  msdelay(1000);
  read();
  if(chanuser[i]=='4')
   {
  buz=0;
  msdelay(8000);
  buz=1;
   }
  else
  {
  buz=0;
  msdelay(400);
  buz=1;
  msdelay(400);
  buz=0;
  msdelay(400);
  buz=1;
  msdelay(400);
  buz=0;
  msdelay(400);
  buz=1;
  msdelay(400);
  buz=0;
  msdelay(400);
  buz=1;
  msdelay(400);
  }
}//Main Ends Here		


void msdelay(unsigned int value)
{
 unsigned int i,j;
 for(i=0;i<value;i++)
 for(j=0;j<100;j++);
}
circuit diagram also attached.
explaining the code...
initailly it save the data's from userid to eeprom and then after a delay(1000) it again reads the data's from eerpom and saves it to chanuser.
in main() program it checks if the data's of chanuser are as same as userid then LED lights up and if the data's are not as same as userid it starts blinking.
but here as u can see the data's of userid and chanuser are same but still it blinks in my circuit. but works well with proteus stimulation.
it does not works well with my circuit means eeprom is not working well...
can anybody please help me out of this...
 

Attachments

  • circuit.JPG
    circuit.JPG
    98.6 KB · Views: 50

Hi,


but here as u can see the data's of userid and chanuser are same
How can we see this?

What data do you write? And what data do you read?

it does not works well with my circuit means eeprom is not working well...
You say userid and chanuser is the same...this tells me EEPROM communication is working properly.

Your description is confusing in this.
Could you please explain.

Klaus
 

At least start and stop condition code is incorrect, check against I2C specification.

startstop.png
 

Did you join pins 31 & 40 on the MCU?
Does the MCU have a proper reset circuit?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top