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; }
but I do not receive any data back from case 58:
// no ACK for data byte case 0x58