problem with pic18f4620 with eeprom 24lc512 via i2c

General discussion on mikroC.
Post Reply
Author
Message
pratik345
Posts: 15
Joined: 18 Mar 2010 04:24

problem with pic18f4620 with eeprom 24lc512 via i2c

#1 Post by pratik345 » 12 May 2010 06:07

hi i want to communicate 24lc512 with pic18f4620...
but i cant communicate with it....

code provided by mikroelectronica is perfectly work with eeprom 24c02. but cant communicate with 24lc512...

so wat change i should to do..

here the code for 24c02 eeprom
its perfectly working....

sbit sw at RA0_bit;
sbit sw_Direction at TRISA0_bit;

void main()
{

unsigned char i;
PORTD = 0;
TRISD = 0;
PORTA = 0; // Configure PORTB as output
TRISA = 1;
ADCON1=0x0F;

I2C1_Init(100000); // initialize I2C communication
for(i=0;i<16;i++)
{
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(i); // send byte (address of EEPROM location)
I2C1_Wr(i); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
Delay_ms(1000);
}
Delay_ms(1000);

i=0;
for(i=0;i<16;i++)
{
if(sw == 0)
{
delay_ms(10);
if(sw==0)
{
delay_ms(2000);
pause: if(sw==0)
{
delay_ms(10);
if(sw==0)
{
goto start;
}
}
goto pause;
}
}


start:I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(i); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA3); // send byte (device address + R)
PORTD = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop();
Delay_ms(1000); // issue I2C stop signal

}
}

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: problem with pic18f4620 with eeprom 24lc512 via i2c

#2 Post by tihomir.losic » 12 May 2010 11:52

Hello,

please, follow this link in order to find solution for your issue:
http://www.mikroe.com/forum/viewtopic.php?t=2567

Thanks.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

Post Reply

Return to “mikroC General”