Listing 3. Read Sensor Data unsigned int readSHT1xData(void) { int iLoop; unsigned int uiBitRead; unsigned int uiMSB=0; unsigned int uiLSB=0; unsigned int uiRetValue; /* Read MSB from SHT1x */ for (iLoop = 0; iLoop < 8; iLoop++) { uiMSB <<= 1; writeSHT1xOne(SCK_SHT); uiBitRead = readSHT1x(DATA_SHT); udelay(2); writeSHT1xZero(SCK_SHT); udelay(2); if (uiBitRead) uiMSB |= 1; } /* Acknowledge sequence; must drive data * line as it is tri-stated at this point */ driveDataLine(DATA_SHT); writeSHT1xZero(DATA_SHT); udelay(2); writeSHT1xOne(SCK_SHT); udelay(2); writeSHT1xZero(SCK_SHT); tristateDataLine(DATA_SHT); udelay(2); /* Read LSB from SHT1x */ for (iLoop = 0; iLoop < 8; iLoop++) { uiLSB <<= 1; writeSHT1xOne(SCK_SHT); uiBitRead = readSHT1x(DATA_SHT); udelay(2); writeSHT1xZero(SCK_SHT); udelay(2); if (uiBitRead) uiLSB |= 1; } /* Don't acknowledge last byte so the device * doesn't transmit the 8-bit CRC as it isn't * really necessary for this application */ uiRetValue = u8tou16(uiMSB, uiLSB); return(uiRetValue); }