CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I2C slave mode : how detect the end of a packet ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
paolo_minazzi



Joined: 02 Feb 2006
Posts: 1

View user's profile Send private message

I2C slave mode : how detect the end of a packet ?
PostPosted: Thu Feb 02, 2006 11:48 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group