bool KEYS::read3Bytes(uint32_t *data, uint8_t reg) { union { uint8_t b[4]; uint32_t w; } datau; datau.w = *data; Wire.beginTransmission(_address); I2CWRITE((uint8_t) reg); Wire.endTransmission(); uint8_t timeout=0; Wire.requestFrom(_address, (uint8_t) 0x03); while(Wire.available() < 3) { timeout++; if(timeout > I2CTIMEOUT) { return(true); } delay(1); } //Experimental datau.b[0] = I2CREAD(); datau.b[1] = I2CREAD(); datau.b[2] = I2CREAD(); *data = datau.w; return(false); }
void I2C_4DI4RO::readGPIO() { unsigned long t; /* Start request, wait for data and receive GPIO values as byte */ Wire.requestFrom(_address, (uint8_t) 0x01); t = micros(); // Time-out = 100uS lastCommandOK = false; while (Wire.available() < 1 && (micros() - t) < 100); if(Wire.available() > 0) lastCommandOK = true; _PIN = I2CREAD(); }
void PCF8574::readGPIO() { #ifdef PCF8574_INTERRUPT_SUPPORT /* Store old _PIN value */ _oldPIN = _PIN; #endif /* Start request, wait for data and receive GPIO values as byte */ Wire.requestFrom(_address, (uint8_t) 0x01); while (Wire.available() < 1) ; _PIN = I2CREAD(); }
bool KEYS::readByte(uint8_t *data, uint8_t reg) { Wire.beginTransmission(_address); I2CWRITE((uint8_t) reg); Wire.endTransmission(); uint8_t timeout=0; Wire.requestFrom(_address, (uint8_t) 0x01); while(Wire.available() < 1) { timeout++; if(timeout > I2CTIMEOUT) { return(true); } delay(1); } // Experimental *data = I2CREAD(); return(false); }