View previous topic :: View next topic |
Author |
Message |
Tony Helinski
Joined: 09 Sep 2003 Posts: 6
|
i2c_isr_state() |
Posted: Tue Sep 20, 2005 6:56 am |
|
|
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
|
|
Posted: Tue Sep 20, 2005 9:24 am |
|
|
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
|
|
Posted: Mon Jan 23, 2006 6:57 am |
|
|
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
|
|
Posted: Tue Feb 14, 2006 2:26 pm |
|
|
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
|
I2C interrupt |
Posted: Thu Feb 16, 2006 11:46 am |
|
|
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
|
|
Posted: Fri Feb 17, 2006 2:15 am |
|
|
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 |
|
|
|