External eeprom Interfacing using I2C..showing Data in LCD

Status
Not open for further replies.

thunaivendan

Member level 3
Joined
Apr 19, 2013
Messages
61
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,288
Location
Chennai, Tamil Nadu, India
Visit site
Activity points
1,733
Hi guys Have a problem on my code..data is not trasmitting in external eeprom and in LCD..I attach my code for I2C and LCD..kindly..check it reply for me guys
 

Attachments

  • I2C_External EEprom.rar
    108.6 KB · Views: 51

Hi,

Ist the hardware: SDA and SCL lines are not pulled up. See the files attached for I2C and LCD (4-bit). When you are writting to an EEPROM care must be taken during the write procedure. The EEPROM takes about 5ms of write time if i remember correctly. Also try to write in the in the following fashion.
Code:
void EEPROM_Write(char Data, unsigned char Address)
{
	I2C_Start();
	I2C_Write(SlavewriteAddress);
	I2C_Write(Address);					// Address to write data
	I2C_Write(Data);
	I2C_Stop();
        TDelayms(5);
}
char EEPROM_Read(unsigned char Address)
{
	I2C_Start();
	I2C_Write(SlavewriteAddress);
	I2C_Write(Address);						// Address to write data
	I2C_Restart();
	I2C_Write(SlaveReadAddress);
	EEPROMREAD = I2C_Read();
	I2C_ACK(0);								// NACK
	I2C_Stop();
}

Enjoy
 

Attachments

  • LCD display.h.txt
    1.4 KB · Views: 87
  • LCD display.c.txt
    2.5 KB · Views: 53
  • i2c.h.txt
    1.6 KB · Views: 51
  • i2c.c.txt
    1.2 KB · Views: 52

Hello friend,

I have seen your whole code, i think you have one mistake in i2c_address function of your code

My suggestion is:

Change this line of code

l_address=address<<1; Here, address = 0xA0, after code execute, l_address = 0x40
l_address+=mode; Here, l_address = 0x41 or 0x40 according to mode.

With

l_address = address | mode; Here, l_address = 0xA1 or 0xA0 according to mode.


Hope this is help you,

Regards,
Ghanshyam
 





Thank u guy...just knnow found the simulation mistake..how to transfer string same the i2c_write function guys

- - - Updated - - -

thank u for best approach surely check it reply soon.....guys

- - - Updated - - -

Sir tell me logic and operation of 4-bit mode lcd in ur attached CODE..MsB send first and LSB...
 

Hi,

For external eeprom interfacing using i2c, i suggest you, please read complete datasheet of AT24C04 IC as reference. This datasheet contain detail read/write process for EEPROM and you can find some sample code for AT24c04 read/write in ASM language which can be converted in C which is exactly match to your EEPROM.

Please use complete English in post write, I don't understand your shorts.

Regards,
 

Sure..i will correct it...
Eventhough i changed logic in address function...data is not shown guy..and i doubt in disp_data() ,i2c_read() function please verify it

void i2c_address(unsigned char,unsigned char);
void disp_data(unsigned char *);
unsigned char i2c_read(unsigned char);
void main()
{
TRISE=0;
PORTE=0;
TRISD=0;
PORTD=0;
TRISC=0xff;
PORTC=0;
ADCON1=0x06;
lcd_init();
i2c_init();
i2c_start();
i2c_address(0xa0,0);
// i2c_ack();
i2c_restart();
i2c_address(0xa0,0);
//i2c_ack();
//i2c_address(0x00,0);
// i2c_ack();
i2c_write(0x05);
//i2c_ack();
i2c_stop();
i2c_ack();
// i2c_wait();
i2c_start();
i2c_address(0xa1,1);
i2c_restart();
i2c_address(0xa1,1);
i2c_read(0);

*value=i2c_read(0);
disp_data((value));
//delay_ms(10);
}


void i2c_address(unsigned char address, unsigned char mode)
{
unsigned char l_address;
l_address=address|mode;
//l_address+=mode;
i2c_wait();
SSPBUF = l_address;
}
unsigned char i2c_read(unsigned char ack)
{
// Read data from slave
// ack should be 1 if there is going to be more data read
// ack should be 0 if this is the last byte of data read
unsigned char i2c_read_data;

i2c_wait();
RCEN=1;
while(RCEN);
while(!BF);
i2c_wait();
if ( ack ) ACKDT=0; // Ack
else ACKDT=1; // NAck
ACKEN=1; // send acknowledge sequence
// i2c_read_data = SSPBUF;
//i2c_wait();
return(SSPBUF);
}
Above function are doubt..and also how to pass data as argument in write function

these are above function doubted..
 

Hi,

In your code, you write 0x05 value at Memory location 0x00, as you pass 0x00 address. but i doubt in reading process, you don't pass 0x00 address from which data read.
I again suggest you, please read complete and carefully datasheet of AT24C04. it has all need sequence for write and read process.

Regards,
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…