Anyone here used the PIC32 peripheral library for I2C? I'm having a=20 hard time with this, and can't find my ICD3 to help diagnose what's=20 happening. I'm continuously reading data from a slave I2C device (PIC18F25K42=20 based), and the master (PIC32MX320F128H) crashes (reboots) regularly. =20 I'm posting about the maser here... Flags on reboot only have the POR and BOR flags set. Adding a bit of=20 bulk capacitance (10uf) does not help. And this is happening with both=20 Pickit3 power or LiPo w/5V DC-DC power. I also don't see a way to=20 change BOR threshold voltage as with other PIC series. Logic analyzer says that it's happening at different points, but always=20 between I2C start and stop. I'm at a loss as to what to test next, but perhaps someone can identify=20 something I'm doing wrong? This is my master code to read data. The=20 delays were put in earlier when testing w/o error-checking, and seems to=20 still help to reduce crashes. HandleI2CErrors() is just a quick function to check and clear=20 arbitration, TX overflow, and RX overflow errors, and also sets an LED=20 to alert me, but that LED stays off. signed int ReadAFEValue(void) { signed int result, inVal, retVal; retVal =3D 1; if (PLIB_I2C_BusIsIdle(I2C_ID_1)) { PLIB_I2C_MasterStart(I2C_ID_1); // Tell AFE to restart result counter and be ready to send data... // delay_us(100); DelayMs(1); if (PLIB_I2C_TransmitterIsReady(I2C_ID_1)) { PLIB_I2C_TransmitterByteSend(I2C_ID_1,0x54); //=20 Slave addr 0x2A in bits 7:1. 1 in LSB =3D read request, or 0 =3D write req.= .. if (PLIB_I2C_TransmitterByteWasAcknowledged(I2C_ID_1)) { // delay_us(100); DelayMs(1); if (PLIB_I2C_TransmitterIsReady(I2C_ID_1)) { PLIB_I2C_TransmitterByteSend(I2C_ID_1,0xB0); =20 // Command for set mode to read_data mode if (PLIB_I2C_TransmitterByteWasAcknowledged(I2C_ID_1)) { HandleI2CErrors(); // Restart... // delay_us(200); DelayMs(1); if (PLIB_I2C_BusIsIdle(I2C_ID_1)) { PLIB_I2C_MasterStartRepeat(I2C_ID_1); HandleI2CErrors(); // Tell AFE we want to read data now... // delay_us(200); DelayMs(1); if (PLIB_I2C_TransmitterIsReady(I2C_ID_1)) { PLIB_I2C_TransmitterByteSend(I2C_ID_1,0x55); // Slave addr 0x2A in bits=20 7:1. 1 in LSB =3D read request, or 0 =3D write req.. if=20 (PLIB_I2C_TransmitterByteWasAcknowledged(I2C_ID_1)) { HandleI2CErrors(); // delay_us(200); DelayMs(1); PLIB_I2C_MasterReceiverClock1Byte(I2C_ID_1); // Get first byte back from=20 AFE. // delay_us(100); DelayMs(1); if=20 (PLIB_I2C_ReceivedByteIsAvailable(I2C_ID_1)) { if=20 (PLIB_I2C_MasterReceiverReadyToAcknowledge(I2C_ID_1)) { result =3D=20 PLIB_I2C_ReceivedByteGet(I2C_ID_1); // TODO -- store this=20 somewhere PLIB_I2C_ReceivedByteAcknowledge(I2C_ID_1, true); // while=20 (!PLIB_I2C_ReceiverByteAcknowledgeHasCompleted(I2C_ID_1)); } } HandleI2CErrors(); // delay_us(200); DelayMs(1); PLIB_I2C_MasterReceiverClock1Byte(I2C_ID_1); // Get second byte back=20 from AFE. // delay_us(200); DelayMs(1); if=20 (PLIB_I2C_ReceivedByteIsAvailable(I2C_ID_1)) { if=20 (PLIB_I2C_MasterReceiverReadyToAcknowledge(I2C_ID_1)) { inVal =3D=20 PLIB_I2C_ReceivedByteGet(I2C_ID_1); // TODO -- store=20 this somewhere PLIB_I2C_ReceivedByteAcknowledge(I2C_ID_1, false); // NAK=20 here is required for last byte result =3D result | (inVal=20 << 8); retVal =3D result; } } HandleI2CErrors(); // DelayMs(1); // delay_us(200); DelayMs(1); while=20 (PLIB_I2C_TransmitterIsReady(I2C_ID_1) =3D=3D 0); // TOD= O=20 -- countdown and timeout here? } else retVal =3D -8; } else retVal =3D -7; } else retVal =3D -6; } else retVal =3D -5; } else retVal =3D -4; } else retVal =3D -3; } else retVal =3D -2; PLIB_I2C_MasterStop(I2C_ID_1); } return retVal; } // ReadAFEValue() Cheers, -Neil --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .