Not aware of this, but I'll check. Slave is a PIC18F25K42 running MCC-generated code structure. I've used this to try and isolate myself from the nit-picky details, but it's more and more looking like I should be setting registers manually like I always do. Cheers, -Neil. On 10/15/2018 4:09 PM, Manu Abraham wrote: > Very hard to read your code, but: > Does your slave support REPEATED START ? Not all slaves do support it. > > Cheers, > Manu > > > > > On Tue, Oct 16, 2018 at 12:09 AM Neil wrote: >> Anyone here used the PIC32 peripheral library for I2C? I'm having a >> hard time with this, and can't find my ICD3 to help diagnose what's >> happening. >> I'm continuously reading data from a slave I2C device (PIC18F25K42 >> based), and the master (PIC32MX320F128H) crashes (reboots) regularly. >> I'm posting about the maser here... >> >> Flags on reboot only have the POR and BOR flags set. Adding a bit of >> bulk capacitance (10uf) does not help. And this is happening with both >> Pickit3 power or LiPo w/5V DC-DC power. I also don't see a way to >> change BOR threshold voltage as with other PIC series. >> Logic analyzer says that it's happening at different points, but always >> between I2C start and stop. >> >> I'm at a loss as to what to test next, but perhaps someone can identify >> something I'm doing wrong? This is my master code to read data. The >> delays were put in earlier when testing w/o error-checking, and seems to >> still help to reduce crashes. >> HandleI2CErrors() is just a quick function to check and clear >> arbitration, TX overflow, and RX overflow errors, and also sets an LED >> 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 dat= a... >> // delay_us(100); >> DelayMs(1); >> if (PLIB_I2C_TransmitterIsReady(I2C_ID_1)) >> { >> >> PLIB_I2C_TransmitterByteSend(I2C_ID_1,0x54); /= / >> Slave addr 0x2A in bits 7:1. 1 in LSB =3D read request, or 0 =3D write r= eq.. >> 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); >> // 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 >> 7:1. 1 in LSB =3D read request, or 0 =3D write req.. >> if >> (PLIB_I2C_TransmitterByteWasAcknowledged(I2C_ID_1)) >> { >> HandleI2CErrors(); >> >> // delay_us(200); >> DelayMs(1); >> PLIB_I2C_MasterReceiverClock1Byte(I2C_ID_1); // Get first byte back from >> AFE. >> >> // delay_us(100); >> DelayMs(1); >> if >> (PLIB_I2C_ReceivedByteIsAvailable(I2C_ID_1)) >> { >> if >> (PLIB_I2C_MasterReceiverReadyToAcknowledge(I2C_ID_1)) >> { >> result =3D >> PLIB_I2C_ReceivedByteGet(I2C_ID_1); // TODO -- store this >> somewhere >> PLIB_I2C_ReceivedByteAcknowledge(I2C_ID_1, true); >> // while >> (!PLIB_I2C_ReceiverByteAcknowledgeHasCompleted(I2C_ID_1)); >> } >> } >> >> HandleI2CErrors(); >> >> // delay_us(200); >> DelayMs(1); >> PLIB_I2C_MasterReceiverClock1Byte(I2C_ID_1); // Get second byte back >> from AFE. >> >> // delay_us(200); >> DelayMs(1); >> if >> (PLIB_I2C_ReceivedByteIsAvailable(I2C_ID_1)) >> { >> if >> (PLIB_I2C_MasterReceiverReadyToAcknowledge(I2C_ID_1)) >> { >> inVal =3D >> PLIB_I2C_ReceivedByteGet(I2C_ID_1); // TODO -- store >> this somewhere >> PLIB_I2C_ReceivedByteAcknowledge(I2C_ID_1, false); // NAK >> here is required for last byte >> result =3D result | (inVa= l >> << 8); >> retVal =3D result; >> } >> } >> >> HandleI2CErrors(); >> >> // DelayMs(1); >> // delay_us(200); >> DelayMs(1); >> while >> (PLIB_I2C_TransmitterIsReady(I2C_ID_1) =3D=3D 0); // = TODO >> -- 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 >> >> >> >> -- >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .