# PIC32MX Harmony i2c Driver

I have a bit of a problem figuring out how harmony i2c driver works. Trying to establish connection between PIC32 and a barometric sensor MS5637 have been a bit of a nightmare for me.

From sensor's datasheet on page 9 we can see that there is a reset sequence and after that a simple prom read. Below you can see what am i trying to do, but I am not quite shure what should I do to make this communication work.

Using MHC the i2c driver is initialized inside System Initialize and then there is my app code.

void send(uint8_t cmd){

//Start i2c
DRV_I2C0_MasterStart();

DRV_I2C0_ByteWrite(0xEC);
DRV_I2C0_WaitForByteWriteToComplete();

//Write command
DRV_I2C0_ByteWrite(cmd);
DRV_I2C0_WaitForByteWriteToComplete();

//Stop i2c
DRV_I2C0_MasterStop();

}

uint16_t value;

send(cmd);

//Start i2c
DRV_I2C0_MasterStart();

DRV_I2C0_ByteWrite(0xED);
DRV_I2C0_WaitForByteWriteToComplete();

value = 256 * DRV_I2C0_ByteRead ();
DRV_I2C0_MasterACKSend();

DRV_I2C0_MasterNACKSend();

//Stop i2c
DRV_I2C0_MasterStop();

return value;
}

//Reset command
send(0x1E);
ShortDelay( 3000 ); //3 ms

uint8_t i;
for (i=0;i<8;i++){
readPROM(0xA0 + i * 2 );
}
}


Response is always 0x00, but should be something different than that.

I forgot to mention when sending any kind of command on the i2c lines the current rises on sensor. Does this mean the sensor is responding?

If there might be anything obvious I am missing, please warn me, because this is the first time for me using the i2c.

• Things to try when debugging something like this (in order): Check your connected to the correct pins by setting to high and testing with a multimeter. Check your setting the port directions correctly for I2C Check you have the correct pull up resistors. Check you are outputting any data with a scope. After you have confirmed your outputting data you can start checking pins on the slave device and double checking the commands are correct. Let us know how you get on – silverscania Nov 25 '15 at 17:34
• Thanks for the debugging advices, but there is where everything stops for me, because I only have multimeter with the ability to measure 20 kHz max. So I set the i2c frequency to 10 kHz and multimeter is not recognising anything. What is the right way to measure i2c clock? Putting one end between pullup resistor and chip pin-out and the other end to the ground? – Nejc Okorn Nov 25 '15 at 19:34
• Yes that's the right connection. But you won't see anything with a multimeter. Just get a cheap USB oscilloscope off eBay, it will save you weeks of debugging. – silverscania Nov 26 '15 at 17:15

After a long time of debugging my own code I started to debug harmony's I2C static driver and notice that inside of DRV_I2C0_MasterACKSend and DRV_I2C0_MasterNACKSend is a checking like

void DRV_I2C0_MasterACKSend(void)
{

}


and all you have to do is to change the if statement to while loop

void DRV_I2C0_MasterACKSend(void)
{