analogdevicesinc / Linduino

Code for the Linduino, An Arduino Uno-based board that is compatible with many Analog Devices evaluation boards
Other
101 stars 101 forks source link

LTC6813 aux channels are configured wrong (data for GPIO9, VREF2 and UVOV flags are never read) #49

Open gudnimg opened 3 years ago

gudnimg commented 3 years ago

I would think that:

ic[cic].ic_reg.aux_channels=9; // LTC6813

Should be:

ic[cic].ic_reg.aux_channels=12; // LTC6813

Because

This is how a_codes is defined in LTC681x.h

/*! AUX Reg Voltage Data structure */
typedef struct
{
  uint16_t a_codes[9]; //!< Aux Voltage Codes
  uint8_t pec_match[4]; //!< If a PEC error was detected during most recent read cmd
} ax;

This contradicts the example code from DC2350AB. I would expect a overflow when i > 8, was this code ever tested?

void print_aux(uint8_t datalog_en)
{
  for (int current_ic =0 ; current_ic < TOTAL_IC; current_ic++)
  {
    if (datalog_en == 0)
    {
      Serial.print(" IC ");
      Serial.print(current_ic+1,DEC);
      for (int i=0; i < 5; i++)
      {
        Serial.print(F(" GPIO-"));
        Serial.print(i+1,DEC);
        Serial.print(":");
        Serial.print(BMS_IC[current_ic].aux.a_codes[i]*0.0001,4);
        Serial.print(",");
      }

      for (int i=6; i < 10; i++)
      {
        Serial.print(F(" GPIO-"));
        Serial.print(i,DEC);
        Serial.print(":");
        Serial.print(BMS_IC[current_ic].aux.a_codes[i]*0.0001,4);        
      }

      Serial.print(F(" Vref2"));
      Serial.print(":");
      Serial.print(BMS_IC[current_ic].aux.a_codes[5]*0.0001,4);
      Serial.println();

      Serial.print(" OV/UV Flags : 0x");
      Serial.print((uint8_t)BMS_IC[current_ic].aux.a_codes[11],HEX);
      Serial.println();
    }
    else
    {
      Serial.print(" AUX, ");

      for (int i=0; i < 12; i++)
      {
        Serial.print((uint8_t)BMS_IC[current_ic].aux.a_codes[i]*0.0001,4);
        Serial.print(",");
      }
    }
  }
 Serial.println("\n");
}
hugoquiroz commented 3 years ago

@GunZi200 I ran across similar issue. with this register. I was attempting to read GPIO6 but based on how struct is aligned/written I was getting VREF2. My simple fix for this was changing

/*! AUX Reg Voltage Data structure */
typedef struct
{
  uint16_t a_codes[9]; //!< Aux Voltage Codes
  uint8_t pec_match[4]; //!< If a PEC error was detected during most recent read cmd
} ax;

to

/*! AUX Reg Voltage Data structure */
typedef struct
{
  uint16_t a_codes[12]; //!< Aux Voltage Codes
  uint8_t pec_match[4]; //!< If a PEC error was detected during most recent read cmd
} ax;