WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation


A complete communication session to read one or more sequential registers from the device. Returns TRUE if successful or FALSE if there was an error.
I2cDevice. readRegisters(startReg,responseLen,response)
Where I2cDevice is the name you have given to the device in Project Designer.
The start register number.
The number of bytes to be received.
The memory address to store the returned the values.
This is the same as the following pseudo code:
// Connect in write mode
i2cStart( WRITE );
// Write the start register
i2cPut( startreg );
// Connect in read mode
i2cStart( READ );
for(size_t i=0; i<responseLen; i++){
    response[i] = i2cGet();
// Hang up
Assuming you have created a 'Generic I2C Device' in Project Designer called myDevice and you want to read the two registers 10 and 11 then you would use:
// Create an array to hold the two byte response
uint8_t response[2];
if( myDevice.readRegisters(10, 2, response) ){
    uint8_t reg10 = response[0];
    uint8_t reg11 = response[1];
    // Communication failed
Note how the C operator 'sizeof' can be used to make sure that the number of bytes being read is actually the same as the number of bytes in the 'response' array by changing the 'read' as follows:-
myDevice.readRegisters(10, sizeof(response), response)
You are encouraged to use this technique as it means that if you decide, later on, to read 4 bytes then you can just change the 'response' definition to:
uint8_t response[4];
and nothing else needs to change.



Valid XHTML 1.0 Transitional