View previous topic :: View next topic |
Author |
Message |
FazerMan
Joined: 24 Sep 2018 Posts: 2
|
Help with I2C_ISR_STATE() |
Posted: Mon Sep 24, 2018 9:31 am |
|
|
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: 19553
|
|
Posted: Mon Sep 24, 2018 10:04 am |
|
|
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
|
Re: Help with I2C_ISR_STATE() |
Posted: Mon Sep 24, 2018 9:32 pm |
|
|
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
|
|
Posted: Tue Sep 25, 2018 9:04 am |
|
|
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! |
|
|
|