I2C Read for PIC32

Thread Starter

RoboticFan87

Joined Sep 12, 2009
38
Hey guys, i wrote a code for the I2C read for my pic32. Basically the pic32 reads from a control chip DS2482-800. which that chip reads from an ID chip DS2401. If you can check my code and tell me if it looks write. its still giving me problems.

Rich (BB code):
unsigned char I2C_Read_Register(void)
{
  
   int result;
   unsigned char data;
   // 1-Wire Read Bytes (Case C)
   //   S AD,0 [A] 1WRB [A] Sr AD,1 [A] [Status] A [Status] A\
   //                                   \--------/
   //                     Repeat until 1WB bit has changed to 0
   //   Sr AD,0 [A] SRP [A] E1 [A] Sr AD,1 [A] DD A\ P
   //
   //  [] indicates from slave
   //  DD data read
   I2CStart(I2C1);
   I2CSetSlaveAddress(I2C1, 0x30, 0, 0);
   if(I2CByteWasAcknowledged(I2C1)){
 result = I2CSendByte(I2C1,0x96);
   }
   if(result == 0){ 
    I2CRepeatStart(I2C1);
   }
   I2CSetSlaveAddress(I2C1, 0x31, 0, 0);
   if(I2CByteWasAcknowledged(I2C1)){
 if (I2CReceivedDataIsAvailable(I2C1)) {
         I2CAcknowledgeByte(I2C1, TRUE);
         data = I2CGetByte(I2C1);
     }
}
I2CStop(I2C1);
   return data;
}
Thank you
 
Top