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

Help with I2C_ISR_STATE()

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



Joined: 24 Sep 2018
Posts: 2

View user's profile Send private message

Help with I2C_ISR_STATE()
PostPosted: Mon Sep 24, 2018 9:31 am     Reply with quote

400/5000
Hello
I'll need your help on the i2c_isr_state () function.
I retrieved a piece of program calling this function, but I use the programming deck "EasyPic V7" and this function is not part of the library!
So I would like to know how is built the function i2c_isr_state ()
Which microcontroller registers are in this function in CCS ?

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Sep 24, 2018 10:04 am     Reply with quote

This is really not a CCS question. Ask on the forum for your compiler.
Look at the manual it tells you what i2c_isr_state returns. It's actually the R/W bit as bit 7, and a counter reset by the start bit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Help with I2C_ISR_STATE()
PostPosted: Mon Sep 24, 2018 9:32 pm     Reply with quote

FazerMan wrote:

So I would like to know how is built the function i2c_isr_state ()
Which microcontroller registers are in this function in CCS ?

This is the .LST file output for an 18F46K22 using SSP1 for i2c.
It shows the registers and bits used for i2c_isr_state(). Note that
@I2C_STATE is the address of a byte in RAM assigned by the compiler
to store the i2c state value. The compiler chooses the address.
Code:

... result = i2c_isr_state();
0003E:  BTFSC  SSP1STAT.ADDRESS  // D_A bit
00040:  GOTO   004A
00044:  CLRF   @I2C_STATE
00046:  BTFSC  SSP1STAT.WRITE  // R_W bit
00048:  BSF    @I2C_STATE.7
0004A:  MOVF   @I2C_STATE,W
0004C:  INCF   @I2C_STATE,F
0004E:  MOVWF  result


If you wrote it in C code, this would do the same thing:
Code:

#byte SSP1STAT = getenv("SFR:SSP1STAT") // Get address of SSP1STAT
#byte SSP1BUF =  getenv("SFR:SSP1BUF") // Get address of SSP1BUF

#bit DA_BIT = SSP1STAT.5
#bit RW_BIT = SSP1STAT.2


static int8 my_i2c_state = 0x03;

int8 my_i2c_isr_state(void)
{
   
if(!DA_BIT)  // If address byte was received
  {
   my_i2c_state = 0;  // Then clear state.

   if(RW_BIT)      // If it is a Read address
      bit_set(my_i2c_state, 7);  // Then set bit 7 of state.
  }   
 
my_i2c_state++;     

return(my_i2c_state); 
}
FazerMan



Joined: 24 Sep 2018
Posts: 2

View user's profile Send private message

PostPosted: Tue Sep 25, 2018 9:04 am     Reply with quote

Thank you for your answers
I will analyze the code in C to see if it can match what I need and modify it as needed!
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