| 298 | |
| 299 | |
| 300 | bool AGS02MA::_readRegister(uint8_t reg) |
| 301 | { |
| 302 | while (millis() - _lastRegTime < 30) yield(); |
| 303 | |
| 304 | #if defined (__AVR__) |
| 305 | // TWBR = 255; // == 30.4 KHz with TWSR = 0x00 |
| 306 | TWBR = 78; // == 25.0 KHZ |
| 307 | TWSR = 0x01; // prescaler = 4 |
| 308 | #else |
| 309 | _wire->setClock(AGS02MA_I2C_CLOCK); |
| 310 | #endif |
| 311 | |
| 312 | _wire->beginTransmission(_address); |
| 313 | _wire->write(reg); |
| 314 | _error = _wire->endTransmission(true); |
| 315 | |
| 316 | // TODO investigate async interface |
| 317 | delay(30); |
| 318 | |
| 319 | if (_wire->requestFrom(_address, (uint8_t)5) != 5) |
| 320 | { |
| 321 | _error = AGS02MA_ERROR_READ; |
| 322 | #if defined (__AVR__) |
| 323 | TWSR = 0x00; // reset prescaler = 1 |
| 324 | #endif |
| 325 | _wire->setClock(_I2CResetSpeed); |
| 326 | return false; |
| 327 | } |
| 328 | for (uint8_t i = 0; i < 5; i++) |
| 329 | { |
| 330 | _buffer[i] = _wire->read(); |
| 331 | } |
| 332 | #if defined (__AVR__) |
| 333 | TWSR = 0x00; // reset prescaler = 1 |
| 334 | #endif |
| 335 | _wire->setClock(_I2CResetSpeed); |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | |
| 340 | bool AGS02MA::_writeRegister(uint8_t reg) |