I need to set up a slave mode I2C. The device need to send out a character according to the character the master device sends
I don't know is the i2c_write() should follow immediate after the i2c_read() or I need to wait under the master device send a read request. I want to know which function is correct.
Code:
#int_SSP
SSP_isr()
{
int state, n;
state = i2c_isr_state();
if(state < 0x80) { // Master is sending data
n = i2c_read();
switch (n) {
case 0:
i2c_write( targetID[ 0 ] );
break;
case 1:
i2c_write( targetID[ 1 ] );
break;
}
if(state >= 0x80) { // Master is requesting data from slave
}
}
OR
Code:
static int n;
#int_SSP
SSP_isr()
{
int state;
state = i2c_isr_state();
if(state < 0x80) { // Master is sending data
n = i2c_read();
}
if(state >= 0x80) { // Master is requesting data from slave
switch (n) {
case 0:
i2c_write( targetID[ 0 ] );
break;
case 1:
i2c_write( targetID[ 1 ] );
break;
}
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum