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.

I2C interfacing with external EEPROM......

Status
Not open for further replies.

RajS

Newbie level 5
Newbie level 5
Joined
Mar 10, 2011
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
Hi......... I am working on with a development board of PIC16F877.. Here i need to interface my PIC with an external EEPROM (AT24C512) using I2C interface... I have been trying a lot to store and retrieve the value in and from the EEPROM... I have been trying a lot to achieve this.. But i cant get that.. Please help me in this.... Please help me in this project of mines..... I just need the method and code for writing to and reading from an EEPROM...

The EEPROM i use is AT24C512.............:sad:
 

What kind of method you are using Hardware based or Software based ? Are you sure that you following the exact method for the I2C communication.
Start -> Device address -> memory address -> ...so on... better you post the methods you followed in detail
 
  • Like
Reactions: RajS

    RajS

    Points: 2
    Helpful Answer Positive Rating
I have used seperate routines for start, stop and repeated start. The problem is that i have been trying to send the address and data to EEPROM through SDA and SCL lines. Which is better to use, ACKDT or interrupt to note the data R/W?
 

if you following the bit banging method,( hope its bit transfer and recieve fuctions are written properly. along with CLK in the SCL line) the following method will give you an idea. If you are storing an int data, jus change char to int and split the data into upper & lowerbytes and store into memory. While reading you should read the bytes in the same manner that you written


Code:
void I2CMEM_writeData(unsigned int addr,unsigned char num,unsigned char* buf) 
{
	unsigned char Haddr=0;
	//unsigned char upbyte = 0,lowbyte = 0;
	Haddr = (unsigned char)((addr & 0xFF00));
	while(!(I2CMEM_idle()));
	I2CMEM_start();
	I2CMEM_writeByte(MEMWRITE);
	I2CMEM_writeByte(Haddr);
	I2CMEM_writeByte((unsigned char)(addr & 0x00FF));

	while(num--)
	{
		//upbyte = (unsigned char)(((*buf)&(0xFF00))>>8);
		//lowbyte = (unsigned char)((*buf)&(0x00FF));
		I2CMEM_writeByte(*buf);
		//I2CMEM_writeByte(lowbyte);
		//I2CRTC_nak();
		buf++;
	}
	I2CMEM_stop();
}

void I2CMEM_readData(unsigned int addr,unsigned char num,unsigned char *ptrtemp)
{
	unsigned char Haddr = 0;
	Haddr = (unsigned char)((addr & 0xFF00));
	while(!(I2CMEM_idle()));
	I2CMEM_start();
	I2CMEM_writeByte(MEMWRITE);							  
      // device address with write operation 
	I2CMEM_writeByte(Haddr);	    // Higher Byte of the address
	I2CMEM_writeByte((unsigned char)(addr & 0x00FF));	// Lower Byte of  
                                                                                     //the address
	I2CMEM_start();
	I2CMEM_writeByte(MEMREAD);
	while(num--)
	{
		if(num > 0)
		{
			*ptrtemp = I2CMEM_readByte(ACK);
			//*ptrtemp = (((*ptrtemp)<<8)|I2CMEM_readByte(ACK));
			ptrtemp++;
		}
		else
		{
			*ptrtemp = I2CMEM_readByte(NO_ACK);
			//*ptrtemp = (((*ptrtemp)<8)|I2CMEM_readByte(NO_ACK));
		}
	}
	//I2CMEM_nak();
	I2CMEM_stop();
}

If more issues exists , better if you post the code , it will helpful to findout the issue.
 

Thanks a lot sir.... I will sure be in touch as soon as possible.....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top