PICPLC v6 with PIC18F4520 - I2C

General discussion on mikroC.
Post Reply
Author
Message
GeorgeTK
Posts: 1
Joined: 30 May 2010 19:14

PICPLC v6 with PIC18F4520 - I2C

#1 Post by GeorgeTK » 02 Jun 2010 22:16

Hello All.
I have a PICPLC v6 with PIC18F4520 and try to understand how to write and read to a EEPROM over I2C Bus(or any). For controlling I try to send the readed data over USART to a PC I do not receive anything on the USART Terminal.
this is my sample code:

unsigned int i;
int temp;

void main(){
OSCCON = 0x70;
USART_init(9600);

I2C_Init(100000);
I2C_Start(); // issue start signal
I2C_Wr(0xA2); // Adress of EEPROM and and select write operation
I2C_Wr(0x00); // send first byte address
for(i=0;i<=15;i++)
{
delay_ms(5);
I2C_Wr(i); // send data to be written
delay_ms(5);
}
I2C_Stop();

do
{
I2C_Start(); // issue I2C start signal
I2C_Wr(0xA2); // Adress of EEPROM amd select write operation
I2C_Wr(0x00); // first word address
I2C_Repeated_Start(); // issue I2C signal start
I2C_Wr(0xA3); // Read

for(temp=0;temp<=15;temp++) {
Usart_Write(I2C_rd(1)); // Read the data (with acknowledge)
Delay_ms(1000); // and send to USART
}
I2C_Stop();
}while (1);
}

Any Help.!!!! I2C error or...
George

Post Reply

Return to “mikroC General”