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.

Communication between PIc and an external EEPROM

Status
Not open for further replies.

Mazen21

Junior Member level 1
Joined
Mar 28, 2011
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,382
Hello,
I need to save some data in a 24LC256 eeprom from a pic, the eeprom work with I2C.
I linked the sda and the scl pin with 2 pull up resistor of 4.7kohm, linked the 3 pins A0 A1 and A2 with the ground.
The eeprom then has the address of 0XA0 for read and 0XA1 for write. This is the PIC program, I'm using a 16F887 with 20mhz crystal:
Code:
unsigned char i = 0;
char txt[4];
void rc(){
     uart1_write(10);
     uarT1_write(13);
}
void main(){
  uart1_init(9600);
  I2C1_Init(100000);
 I2C1_Start();
  I2C1_Wr(0xA0);
   delay_ms(10);
  I2C1_Wr(0x00);
  delay_ms(10);
  I2C1_Wr(0x00);
   delay_ms(10);
  I2C1_Wr(10); //donnée à écrire
  delay_ms(10);
  I2C1_Stop();
  Delay_100ms();
  I2C1_Start();
  I2C1_Wr(0xA1);
    delay_ms(10);
  I2C1_Wr(0x00);
     delay_ms(10);
  I2C1_Wr(0X00);
  delay_ms(10);
  I2C1_Repeated_Start();
  I2C1_Wr(0xA1);
  delay_ms(10);
  i=I2C1_Rd(0);
  I2C1_Stop();
  bytetostr(i,txt);
  uart1_write_text(txt);
  rc();
}
I think I did it all but The simulation in proteus ISIS always shows me that I'm reading 255.
Please any suggestion and Ideas.
Thanks
 

hy mazen
plz attach i2c debugger with the data and clk pin. it will work.
and in real time h/w ur code will work.
 

h/w is hardware.proteus dont show the correct simulation of eeprom check it on the real hardware implementation thats what she meant .
 

Hello, glad to tell that it work, my mistake was in addressing the second time (line 22 from the start) I should write the address of the eeprom in the right form.
I changed the I2C1_Wr(0xA1); with I2C1_Wr(0xA0);
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top