sparkfun / SparkFun_STUSB4500_Arduino_Library

Communicates with the STUSB4500 over I2C to easily add USB-C Power Delivery into your project.
https://www.sparkfun.com/
Other
15 stars 10 forks source link

writing PDO2 voltage #6

Closed paulvha closed 3 years ago

paulvha commented 3 years ago

Looking at the code for "write" the value of PDO2 voltage in NVRAM is done with:

    // PDO2
   sector[4][1] = voltage[1] / 0.2; //load Voltage (sector 4, byte 1, bits 0:7)

Looks to me this is not using the correct way to save it. why not apply the same approach for PDO3 (but then on a different place in the sectors)

    // PDO2 
    // Load voltage (10-bit)
    // -bit 9:2 - sector 4, byte 1, bits 0:7
    // -bit 1:0 - sector 4, byte 0, bits 7:6
    digitalVoltage = voltage[1] / 0.05;   //convert voltage to 10-bit value
    sector[4][0] &= 0x3C;                 //clear bits 7:6
    sector[4][0] |= (digitalVoltage<<8);  //load bits 1:0
    sector[4][1] = 0xFF & (digitalVoltage >> 2); //load bits 9:2

regards, Paul

awende commented 3 years ago

Thanks for pointing this out. This has been fixed with V1.1.5 release