diff options
Diffstat (limited to 'libraries/Wire/Wire.cpp')
-rw-r--r-- | libraries/Wire/Wire.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 553add7..835b794 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -80,8 +80,26 @@ void TwoWire::setClock(uint32_t frequency) TWBR = ((F_CPU / frequency) - 16) / 2; } -uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop) { + if (isize > 0) { + // send internal address; this mode allows sending a repeated start to access + // some devices' internal registers. This function is executed by the hardware + // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers) + + beginTransmission(address); + + // the maximum size of internal address is 3 bytes + if (isize > 3){ + isize = 3; + } + + // write internal register address - most significant byte first + while (isize-- > 0) + write((uint8_t)(iaddress >> (isize*8))); + endTransmission(false); + } + // clamp to buffer length if(quantity > BUFFER_LENGTH){ quantity = BUFFER_LENGTH; @@ -95,6 +113,10 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop return read; } +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) { + return requestFrom((uint8_t)address, (uint8_t)quantity, (uint32_t)0, (uint8_t)0, (uint8_t)sendStop); +} + uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) { return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true); |