allenhuffman
Joined: 17 Jun 2019 Posts: 638 Location: Des Moines, Iowa, USA
|
PIC24 PCD compiler and MPLAB X compiler I2C? |
Posted: Thu Oct 02, 2025 4:01 pm |
|
|
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. |
|