Skip to content

No Wire.endTransmission() after a Wire.requestFrom() please. #9

@Koepel

Description

@Koepel

In the file "MPR121.cpp" in the function getRegister(), there is a Wire.endTransmission() directly after a Wire.requestFrom().

The Wire.endTransmission() should only be used when writing data and only in combination with Wire.beginTransmission() and almost always with Wire.write().

To test if valid data was received, the return value could be used, as is done in the other functions. However the function getRegister() can not return a 'false' like the other function.

This is not okay:

    Wire.requestFrom(address,(unsigned char)1);  // just a single byte
    if(Wire.endTransmission()!=0){
    	error |= 1<<ADDRESS_UNKNOWN_BIT;
    } else {
    	error &= ~(1<<ADDRESS_UNKNOWN_BIT);
    }
    scratch = Wire.read();

Perhaps this is better:

    if(Wire.requestFrom(address,(unsigned char)1) == 1){  // just a single byte
      error &= ~(1<<ADDRESS_UNKNOWN_BIT);
      scratch = Wire.read();
    } else {
      error |= 1<<ADDRESS_UNKNOWN_BIT;
    }

But I'm not sure if that is how you want to deal with an error.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions