This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C Read Problem

Hello,
I am trying to write a Set of Bit Bang I2C Functions to communicate with a SRF08 Range Finder. I found some code by Grant Beattie for the HC11 and have addapted it for the 89LPC932. Now I have the Start, stop, and Write Byte functions working, but the Read function is not working. I have the suggested pull-up resistors and when I run the code the value outputs 255 meaning the data line never falls. This is my code please help.

unsigned char I2cRead(unsigned char count)
{
unsigned char mask;
unsigned char value;
unsigned char index = 0;

while(count)
   {
   mask  = 0x80;
   value = 0x00;
   while(mask)      // Do the 8 data bits...
      {

      SclHi();       // Set SCL
                  //and wait for it to go hi.

     I2cDelay();

      if( GetSda() ) // Read the bit
         value |= mask; // the returned byte.

      SclLo();  // Bring SCL low again
      I2cDelay();
      mask >>= 1;
      }

  Readvalue = value;   // Save the read byte.

   index++;
   count--;
   if(count) // If not the last byte, ACK
      {
      SdaLo();      // Bring SDA low for ACK.
      SclHi();      // Clock high.
      I2cDelay();
      SclLo();      // Clock low.
      SdaHi();      // Release SDA.
      I2cDelay();
      }
   }

SdaHi();   // SDA high for NACK on last byte.
SclHi();       // Clock high.
I2cDelay();
SclLo();       // Clock low.
I2cDelay();

return 0;
} 

Parents Reply Children
No data