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 CCS Technical Support

I2C state values

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



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

I2C state values
PostPosted: Fri Oct 21, 2016 11:08 am     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Fri Oct 21, 2016 11:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 21, 2016 11:35 pm     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Sun Oct 23, 2016 1:18 am     Reply with quote

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.
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