Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I2c communication usinf PIC16F876A with EEPROM(M24C64)

Status
Not open for further replies.

RedEyz

New Member
Hi im student and im stuck in using built in i2c i dont know if the header file is working properly or not can any one plz help me with this.

i am using IAR embedded Workbench v2.21
PPPv3 to burn hex file
E-Block Matrix Multimedia is being used

3.2768 Mhz Xtal

E0=E1=E2=GND
100nF Capacitor across +5v and GND
4k7 Ω 2 resistors one in SCL and one in SDA
i want to see the results on the LCD.

please tell me whats wrong with my header file i have taken it from some online and its seams to show no error in my compiler but it does not work.
 

Attachments

  • FINAL YEAR..c
    2.6 KB · Views: 152
  • LCDdrive..c
    6.8 KB · Views: 136
  • i2c..h
    1.8 KB · Views: 144
When you write to a serial eeprom there is a delay whilst the write takes place and in this time the chip doesn't respond at all. To ensure the chip is responding you have to wait for an acknowledge after sending the ID (0xa0). If no ACK is received you have to send a stop and do it all again.

Assuming the library routines you are using return a boolean to signify ACK/NACK then something like this should work.
Code:
void write_ext_eeprom(unsigned short address, unsigned char data)
{
    i2c_start();
    while(i2c_write(0xa0)==0){	//if no ACK
	i2c_stop();		//then stop
	i2c_start();		//and restart
    }
    i2c_write((address >> 8) & 0xFF);
    i2c_write(address & 0xFF);
    i2c_write(data);
    i2c_stop();
    del();
}

Check the manual of your compiler as it may return true for an NACK.

You will also need to modify the read function.

Edit, just looked at I2C.h and i2c_write does return 1 if an ACK is received.

Mike.
 
Last edited:
Hi thanks pommie for reply. i have tried ur idea, now what is happening is the data is being sent its sends the acklegement that data is sent but it does not recieve it it show me 255 output please help
 

Attachments

  • FINAL YEAR..c
    2.8 KB · Views: 138
  • i2c..h
    2 KB · Views: 320
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top