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

PDO values are not being stored in NVM #9

Closed faircm2 closed 11 months ago

faircm2 commented 11 months ago

I have the following problem. I set the PDO values for PDO2 and PDO3 to 15V/3A and 20V/5A resp., using a modified version of Example2-SetParameters.ino:

`#include

include

STUSB4500 usb; double voltage; int pdo_number;

void setup() { Serial.begin(115200); Wire.begin(); //Join I2C bus

delay(500);

/* The Power Delivery board uses the default settings with address 0x28 using Wire.

 Opionally, if the address jumpers are modified, or using a different I2C bus,
 these parameters can be changed here. E.g. usb.begin(0x29,Wire1)

 It will return true on success or false on failure to communicate. */

if(!usb.begin()) { Serial.println("Cannot connect to STUSB4500."); Serial.println("Is the board connected? Is the device ID correct?"); while(1); }

Serial.println("Connected to STUSB4500!"); delay(100);

/ Set Number of Power Data Objects (PDO) 1-3 / usb.setPdoNumber(3);

/* PDO1

void loop() { pdo_number = usb.getPdoNumber(); Serial.print("PDO Number: "); Serial.println(pdo_number);

voltage = usb.getVoltage(pdo_number); Serial.print("Voltage3 (V): "); Serial.println(voltage);

delay(1000); }`

After running this code on the RedBoard, and then pressing the reset button on the PowerDeliveryBoard, the orange LED for PDO3 on the PowerDeliverBoard lights up and on the Serial Monitor I get PDO3 with 20V/5A. So far so good.

When I detach the RedBoard from the PowerDeliveryBoard, the LED is still orange, but with less luster. Then when I detach the USB-C connector coming from the Anker PowerBank 737 from the PowerDeliveryBoard, the PDO3 LED goes dark, as it should (no power). When I reconnect the USB-C coming from the Anker PowerBank 737, I would expect the PowerDeliveryBoard to cold start and then go into default mode, which I thought would now be the programmed PDo3. However the LED fro PDO3 stays dark and the PowerDeliveryBoard only delivers 5V. When I reattach the RedBoard to the PowerDeliveryBoard, and then press the reset button on the PowerDeliveryBoard, the PDO3 LED on the PowerDeliveryBoard lights up orange again.

I thought that the code would program the NVM with the new PDO values, and then when the PowerDeliveryBoard boots, it would read those values into the I2C and automatically switch to PDO3, with the LED going orange.

What am I doing wrong here?

ardnew commented 11 months ago

You should try flashing Example1-ReadParameters.ino to your RedBoard to inspect what was actually written to NVM. The contents of NVM will not be different from whatever was written using your modified example sketch. And please post the output you get on the serial monitor from the Example1 sketch.

This way you can verify the PDO values you set are being saved correctly, and that the problem is something else.

faircm2 commented 11 months ago

Thanks for your quick answer. I was reading some of the other posts, and found this entry by awende: https://github.com/sparkfun/SparkFun_STUSB4500_Arduino_Library/issues/3#issuecomment-784356538

I ran into an issue where one or more of the NVM bytes would have the wrong value written to them. As a result, you could change the PDO settings, but the board would stay at 5V.

Lower down in the thread, there is a sample program by infamy called [USBC_PPv1.txt]. I ran that first with usb.write(DEFAULT), and then uncommenting the new PDO-entries, which I modified for myself, I ran this code with usb.write(). Now the orange LED turns on when I plug the Power Delivery Device into the PowerBank. So it seems that the modifications were not actually written into the NVM, even though the values which I had tried writing in were read out correctly using the sample program under Example1-ReadParameters.