Hi, I am trying to use I2C to send 0x00 or 0x01 from master to slave and the slave will light an LED if it receives 0x01, and not light the LED if it receives 0x00. I tested the code and the LED doesn't light up at all. I'm using PIC 18F4620 and CCS compiler. Anyone knows the reason why? The master and slave codes are as follows:
Master:
Slave:
Master:
Rich (BB code):
#define SLAVE1_WRT_ADDR 0x12 //LSB=0
#define SLAVE1_READ_ADDR 0x13 //LSB=1
//====================================
void main()
{
int8 cmd;
while(1)
{
if(input(PIN_C0))
cmd = 0x01;
else
cmd = 0x00;
i2c_start();
i2c_write(SLAVE1_WRT_ADDR);
i2c_write(cmd);
i2c_stop();
//printf("read %X \n\r", data);
}
}
Rich (BB code):
int8 data;
#INT_SSP
void ssp_interrupt()
{
int8 incoming, state;
state = i2c_isr_state();
if(state < 0x80) // Master is sending data
{
incoming = i2c_read();
data = incoming;
}
if(state >= 0x80) // Master is requesting data from slave
{
i2c_write(data);
}
}
//======================================
void main ()
{
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
//set_tris_c(0x01);
while(1)
{
if (data == 0x01)
output_high(PIN_C0);
if (data == 0x00)
output_low(PIN_C0);
}
}