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_isr_state()

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



Joined: 09 Sep 2003
Posts: 6

View user's profile Send private message

i2c_isr_state()
PostPosted: Tue Sep 20, 2005 6:56 am     Reply with quote

Has anyone tried this function yet? It looks like it might simplify the i2c
interface. Looking at the example code provided (EX_SLAVEE.C),

#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0)
BYTE address, buffer[0x10];

#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;
state = i2c_isr_state();
if(state < 0x80) //Master is sending data
{
incoming = i2c_read();
if(state == 1) //First received byte is address
address = incoming;
if(state == 2) //Second received byte is data
buffer[address] = incoming;
}
if(state == 0x80) //Master is requesting data
{
i2c_write(buffer[address]);
}
}

The question I have is, what information does the state value from
the isr return provide? Is it a count of the number of bytes received
before the stop bit has been set? Or is it something else?
Any info would be appreciated.
Thanks
Tony
Guest








PostPosted: Tue Sep 20, 2005 9:24 am     Reply with quote

Well, after playing with this function for awhile these are my findings.

As I suspected the state byte is the number of bytes sent before the
stop bit. Notice in the example that CCS starts to collect data after the
first read. This is because the data in the first read (state = 0) is the
same as the data in the second read (state = 1).

Other than the data in both the state[0] byte and the state[1] byte
being the same this function seems to work very well (easy).

Receiving multiple bytes is as easy as:

#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;

state = i2c_isr_state();

if(state < 0x80) //Master is sending data
{
incoming = i2c_read();
//First received byte is address
if(state >= 1)
i2c_rcv_buffer[state - 1] = incoming;
// Test your buffer here
}
}

I hope this helps

Tony
PICLeo



Joined: 14 Dec 2005
Posts: 11
Location: South Africa

View user's profile Send private message ICQ Number

PostPosted: Mon Jan 23, 2006 6:57 am     Reply with quote

Hi

I tried to use the i2c_isr_state() routine within my program but it is not possible to compile the program. I also don't find it within the help files. Doesn't it exist in all versions?
I use version 3.212. Is it maybe a too old version of the compiler?

Bye
Ale
Guest







PostPosted: Tue Feb 14, 2006 2:26 pm     Reply with quote

Yes, indeed, your version is too old. The function has been introduced in version 3.231.
linhnc308



Joined: 16 Feb 2006
Posts: 9
Location: Viet Nam

View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger

I2C interrupt
PostPosted: Thu Feb 16, 2006 11:46 am     Reply with quote

how to use pic in Slave mode. I had programed for my F877a and 876a to communications them via I2C. When i transfer one byte from master(877a) to slave(876a), it's ok, but when i call i2c_write(address_slave + bit 1 at the end) to read from slave(876a) but it not work well.
Please show me the problem and if you have, send me the code.
Thank!
PICLeo



Joined: 14 Dec 2005
Posts: 11
Location: South Africa

View user's profile Send private message ICQ Number

PostPosted: Fri Feb 17, 2006 2:15 am     Reply with quote

Hi

I do have a working code over there. Maybe it helps you.
Just look for the int_ssp interrupt at the slave Pics. Maybe the code from Slave 2 is more easy to understand. The routines don't work for the slave PIC.

Bye

http://www.ccsinfo.com/forum/viewtopic.php?t=26034
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