paolo_minazzi
Joined: 02 Feb 2006 Posts: 1
|
I2C slave mode : how detect the end of a packet ? |
Posted: Thu Feb 02, 2006 11:48 am |
|
|
I have 2 doubts about i2c slave mode using interrupt.
In this case the interrupt routine should be similar to this:
#int_ssp
void isr_routine()
{
char tmp=i2c_isr_state();
if (tmp==0)
{ // received a START + I2C_ADR
}
else
if ((tmp>=1) && (tmp<=0x7F))
{ // received a byte.
// i2c_read() must be used to read the byte
}
else
if (tmp==0x80)
{ // received a START + ( I2C_ADR | 1)
// i2c_write(data) must be used to write a byte
}
else
if (tmp>0x80)
{ // master has read the byte sent by the slave.
// i2c_write(data) must be used to write a byte
}
}
The FIRST is to understand when the master has read the LAST byte, that is when it doesn't want bytes anymore.
When it occours, the master should send a NOACK and STOP, otherwise it should send an ACK.
I know that should be possible to use
ack=i2c_write(data)
and read the ack variable.
But in my experience this doesn't work.
ack is always 0, that is an ACK !!!
The SECOND problem is that after the NOACK sent by the master, the PIC receives an other intewrrupt.
Is there a clean and secure method to understand the end of a i2C packet when the PIC is in slave mode ?
Thanks !
Paolo Minazzi |
|