View previous topic :: View next topic |
Author |
Message |
info@ckmintech.com
Joined: 16 May 2006 Posts: 39
|
I2C Slave |
Posted: Thu Nov 05, 2009 8:13 am |
|
|
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;
}
}
|
Thanks for the help.
Rgds. |
|
 |
epitalon Guest
|
|
Posted: Thu Nov 05, 2009 9:35 am |
|
|
2nd solution, of course |
|
 |
|