View previous topic :: View next topic |
Author |
Message |
silelis
Joined: 12 Jun 2007 Posts: 68 Location: Poland, podlaskie district
|
I2C state values |
Posted: Fri Oct 21, 2016 11:08 am |
|
|
Hello,
I want to write some extended i2c procedure which will send variable amount of bits to some PIC2PIC i2c routine.
I understand how slave interrupt works but I wonder how in interrupt it detects if i2c state is "STOP" which will mean to the slave that it can process received data.
Something like this:
Code: |
char receive_buffer[64];
int buffer_position=0;
int1 transmition_ended = FALSE;
#int_SSP // interrupt on i2c activity
int state, incoming;
state = i2c_isr_state();
if(state < 0x80)
{
incoming = i2c_read(I2CS);
if (state == 1)
{
cmd = incoming;
}
else if (state > 1)
{
receive_buffer[buffer_position]=incoming;
buffer_position =buffer_position+1;
}
else if (state == STOP_VALUE)
{
buffer_position = 0;
transmition_ended = TRUE; // var which will allow main function to process data
}
}
else
{
i2c_write(I2CS,wrt_buf[state-0x80]);
}
}
|
+++++++++++++++++++++++++
- Post moved to General Discussion forum.
silelis,
Please post questions in the General Discussion forum,
not in the Code Library.
- Forum Moderator
+++++++++++++++++++++++++ |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Oct 21, 2016 11:39 am |
|
|
No.
The PIC doesn't normally interrupt on start or stop. To have it do this you have to set an extra bit (bit 3 of the SSPxCON1 register).
Then to detect the stop in the interrupt, you would have to test the S bit (bit 3 SSPxSTAT).
Updated.
Looking at what you post, it won't work anyway. In state 0x80, you must read before writing. |
|
|
silelis
Joined: 12 Jun 2007 Posts: 68 Location: Poland, podlaskie district
|
|
Posted: Fri Oct 21, 2016 11:35 pm |
|
|
Ttelmah wrote: | No.
The PIC doesn't normally interrupt on start or stop. To have it do this you have to set an extra bit (bit 3 of the SSPxCON1 register).
Then to detect the stop in the interrupt, you would have to test the S bit (bit 3 SSPxSTAT).
Updated.
Looking at what you post, it won't work anyway. In state 0x80, you must read before writing. |
But I can test this bit in main loop? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Oct 23, 2016 1:18 am |
|
|
Honestly it is better to have your data packet, having a 'update complete' bit or byte, which you write to after the rest of the data is sent.
There are problems with trying to detect start/stop, since this will trigger for all the devices on the bus. |
|
|
|