Skip to content

No need to wait after Wire.requestFrom() and it should not be used together with Wire.beginTransmission(). #3

@Koepel

Description

@Koepel

In the file "FOSSASAT-1/Code/FossaSat1/power_control.cpp", in the function "Power_Control_INA2256_Check()", there is Wire.beginTransmission() just before the Wire.requestFrom(). That Wire.beginTransmission() may be removed.
The timeout after the Wire.requestFrom() may be removed as well.

Explanation: Common-mistakes, number 1 and 3.

This section:

  // try to read
  Wire.beginTransmission(INA_ADDR);
  Wire.requestFrom((uint8_t)INA_ADDR, (uint8_t)2);
  uint32_t start = millis();
  while(!Wire.available()) {
    if(millis() - start >= INA_TIMEOUT) {
      // timed out
      return(false);
    }
  }

can be reduced to:

  // try to read
  Wire.requestFrom((uint8_t)INA_ADDR, (uint8_t)2);

If you want to check if the data was received, then you can do this:

  // try to read
  Wire.requestFrom((uint8_t)INA_ADDR, (uint8_t)2);
  if(Wire.available() != 2) {
    return(false);
  }

or this:

  // try to read
  if(Wire.requestFrom((uint8_t)INA_ADDR, (uint8_t)2) != 2)
    return(false);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions