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

Reproducing a CCS convenience function in XC16?

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



Joined: 19 Dec 2012
Posts: 43
Location: Connecticut, USA

View user's profile Send private message

Reproducing a CCS convenience function in XC16?
PostPosted: Fri Sep 05, 2014 10:04 am     Reply with quote

Hi all,

I've got an interesting situation on my hands and I'm hoping someone here might be familiar enough with the CCS built in functions to shed some light on it.

I'm working on some I2C code with the XC16 toolchain from microchip and I'm thinking it will be much easier for me to port over some already working code that has been written in CCS rather than having to do it over from scratch. Of course this means bringing over the CCS function that gives me the status of the I2C transaction.

The function in question I'm trying to reproduce is the I2C_ISR_STATE() function.

From what I can gather, this function could be reproduced in code as such:

Code:

uint8_t i2c_isr_state(void){
    uint8_t state;
    if (I2C1STATbits.D_A == 0){ /*address match received*/
        if (I2C1STATbits.R_W == 1){
            state = 0x80;   /*Master is requesting data*/
        } else {
            state = 0;      /*Master is sending data*/
        }
        I2C_ISR_State = state;
    } else {
        I2C_ISR_State++;  /*Data Byte from master, increment state*/
        state = I2C_ISR_State;
    }
    return state;
}


In this situation I2C_ISR_State is a global that is set to either 0 or 0x80 when an address is received and incremented from there for each successive byte. As far as I can see, I should never need to reset I2C_ISR_State outside this function as it should reset itself at the beginning of each I2C Transaction.

I'm running into issues getting the code in my new XC16 SI2C1 ISR to work reliably and I'm just trying to confirm that my new I2C_ISR_STATE function should (at least in theory) perform the same action as the one built into CCS (so I can at least rule it out as a potential issue).


Any insight is greatly appreciated!
KTrenholm



Joined: 19 Dec 2012
Posts: 43
Location: Connecticut, USA

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 12:33 pm     Reply with quote

Okay I resolved my issues I was having. The issue was in the layout of my ISR. The function I posted does seem to be a suitable port of the convenience function.

However I did turn the I2C_ISR_State global into a static local variable just to have one less global hanging around.

Code:

uint8_t i2c_isr_state(void){
    static uint8_t i2c_state;
    if (I2C1STATbits.D_A == 0){ /*address match received*/
        if (I2C1STATbits.R_W == 1){
            i2c_state = 0x80;   /*Master is requesting data*/
        } else {
            i2c_state = 0;      /*Master is sending data*/
        }
    } else {
        i2c_state++;
    }
    return i2c_state;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 05, 2014 12:38 pm     Reply with quote

For reference:
http://www.ccsinfo.com/forum/viewtopic.php?t=26477
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