I wanted to develop a USB Power Delivery SINK project using my STM32G431KBU3 MCU.
For that reason, I have designed a custom PCB and follwed carefully ST's WiKi:
I have successfully created an advanced SINK aplication in which I can negotiate Up to 6 different PDOs. I have used ADC2 Channel2 to read VBUS regarding my PCB demanded that.
The point is, everything works OK but, when trying to use ADC1 for other purposes of my aplication, USBPD negotiation stops working. Only configuring ADC1 in CUBE makes USBPD stops working. I didn't use ADC1 functions yet.
When sniffing USBPD trace, I can notice that something is wrong with ADC2 Channel2, the one which monitors VUSB.
So, my question is, are ADC1 and ADC2 not compatible in this USBPD SINK application? Is there any way to use ADC1 without stopping ADC2 and USBPD app??
Thank you in avance!
Hello @CGonz.5 ,
Can you share the trace you are talking about ?
There shouldn't be any issue using another ADC for you application. Is your ADC1 initialized at the same time that the ADC2 ? If you followed the wiki, did you change the used ADC to ADC2 in function BSP_USBPD_PWR_VBUSGetVoltage ?
I case you are now aware of it, you can find a complete project, created by CubeMX and using a G474RE in x-cube-tcpp here.
Here is the trace I can se when no configuring ADC1, only using ADC2 - Channel 2 for the USB-PD application. Everything is OK:
Then, I just configure ADC1 - Channel 3. Generation code from CUBE, no any code or ADC usage, compilation and here is what i got:
Yes, I changed ADC1 to ADC2 in function BSP_USBPD_PWR_VBUSGetVoltage , here is the code:
If you notice, the new trace of USBPD, it seems that VBUS is being read wrong, as if now the application is getting VDDA_APPLI from ADC1 rather than ADC2 as configured previously...
What do you think?
Thank you in advance,
It seems that you ADC2 is weirdly configured.
Do you mind sharing your code ? Or at least the MX ADC (for both ADC) initialization functions and the order they are called at the start of you main?
Find it attached.
I will try another approach... I will map my 3 analog inputs to 3 different channels of ADC1:
When I use this configuration, USBPD keeps working good, but now I have to access to Channel 1 and 3 as well.
I see USBPD uses "LL_ADC_REG_ReadConversionData12(ADC1)" to read VSENSE, but I don't know what this macro does, how it reads ADC1 Channel2 if that channel 2 is not specified in the argument, only ADC1 is specified...
How can I read Channel 1 and 3 without changing anything or interferring into Channel 2?
I don't see anything in your main and msp files that can wrongly or reconfigure the ADC, your CubeMX screenshots looks good too. The issue could also comes from the user code you added alongside the wiki example.
Regarding your second question, as PA1 can be set to ADC1 ch2 or ADC2 ch2, yes you can use the same ADC for your application than for USBPD. You will need to modify a bit BSP_USBPD_PWR_VBUSGetVoltage function in order for it to sense the right channel, as the base example provided by the wiki assumes you only have the VBUS channel configured in your ADC. That is why LL_ADC_REG_ReadConversionData12 is used, this functions just reads the conversion result of the ADC (The ADC can only read one channel at a time), and because only one channel is configured, this result is the result of this channel.
In you case with multiple channels, you will need to use something else. As you are already using a DMA, I suggest the DMA can fill an array with the results of the conversions of the three channels, and function BSP_USBPD_PWR_VBUSGetVoltage can read this array (at the index corresponding the the VBUS channel) instead of using LL_ADC_REG_ReadConversionData12.