Anyone have an idea about how to connect Arduino Uno to PIC18F4620, the following circuit illustrates what I mean:
I want to use Arduino as a master and 2 PIC18F4620 microcontrollers as slaves, the first PIC on address 0x50 and the second one on 0x51.
I used the following code to program the Arduino as master:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
Wire.beginTransmission(0x50);
Wire.write('I');
Wire.write('2');
Wire.write('C');
Wire.write('\n');
Wire.endTransmission();
Serial.println("Send to I2C Slave 0x50");
delay(1000);
}
The following code for the PIC using CCS compiler:
#include <slave.h>
#use rs232(stream=string,baud=9600, xmit=PIN_C6, rcv=PIN_C7,parity = N, bits = 8)
#define P_SDA PIN_C4
#define P_SCL PIN_C3
#use i2c(slave, sda=P_SDA, scl=P_SCL,address=0x50)
void main()
{
char data;
char buffer_I2C[10];
int i=0;
printf("SLAVE\r\n");
while(TRUE)
{
if(i2c_poll())
{
data = i2c_read();
printf("%d \r\n" ,data);
if(data != -96)
{
if(data == '\n')
{
if(buffer_I2C[0] == 2)
{
buffer_I2C[i]='\0';
printf("Message - %s\r\n",buffer_I2C);
}
}
else
{
buffer_I2C[i]=data;
i++;
}
}
else
{
i=0;
}
}
}
}
The problem is the Arduino does not send anything to PIC. What is the problem?