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

PIC24 PCD compiler and MPLAB X compiler I2C?

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



Joined: 17 Jun 2019
Posts: 638
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PIC24 PCD compiler and MPLAB X compiler I2C?
PostPosted: Thu Oct 02, 2025 4:01 pm     Reply with quote

I have been trying to make common source files that work with our CCS PCD projects and a new one that is using the MPLAB X compiler.

I have been unable to find examples of this "Foundation Services Library" I2C code, and neither A.I. I have tried to use has produced code that fully works.

Original:

Code:
bool AD5272WriteCommandData (unsigned int address, uint8_t command, uint16_t data)
{
    bool status = false;
    uint16_t value = (((uint16_t)command & AD5272_CMD_MASK) << 10) | (data & AD5272_DATA_MASK);

    //AD5272_PRINTF ("AD5272WriteCommandData (0x%x, 0x%x, 0x%x)\r\n", address, command, data);

#if defined(__PCD__) // CCS PCD compiler.
    unsigned int ackStatus = 0;

    // Send start condition
    i2c_start (AD5272_I2C_STREAM);
   
    // Send address with write bit (0)
    ackStatus = i2c_write (AD5272_I2C_STREAM, address << 1);
    if (ackStatus == 0)
    {
        // ACK'd, so something is there, continue writing.
        i2c_write (AD5272_I2C_STREAM, value >> 8);
        i2c_write (AD5272_I2C_STREAM, value & 0xff);
       
        status = true;
    }
   
    // Send stop condition
    i2c_stop (AD5272_I2C_STREAM);

#else // assume MPLAB X compiler.

     ...snip...

#endif

    return status;
}


Does anyone here work with both systems?

The code that was presented to me in MPLABs uses "void i2c2_waitForEvent(uint16_t*);" over there, and looks like it may require some steps to have interrupts working.

I am using a PIC24FJ1024GA606 for this project, but I am happy with a polled I2C approach like we do in CCS. This MPLAB code looks like it wants interrupts, since that wait function is looking at slave and master IRQ bits.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?

Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002.
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