USB-C VBUS measurement

Hi there,

I want to measure VBUS without any external circuitry and came across the USB-C VBUS Zephyr API.

Is this API suitable for what I'm after? If so, do I need to sacrifice one or multiple pins for this purpose?

I found some relevant KConfig options options. In my prj.conf, I can enable the CONFIG_USBC_VBUS_DRIVER Kconfig option. However, when trying to enable CONFIG_USBC_VBUS_ADC, I get the "CONFIG_USBC_VBUS_ADC was assigned the value y, but got the value n. Missing dependencies: DT_HAS_ZEPHYR_USB_C_VBUS_ADC_ENABLED" warning. There's no CONFIG_DT_HAS_ZEPHYR_USB_C_VBUS_ADC_ENABLED Kconfig option, and I'd think that I can resolve this warning by adding the relevant node in the devicetree.

Based on the USB-C device stack page, I tried to add the following devicetree nodes:

port1: usbc-port@1 {
	compatible = "usb-c-connector";
	reg = <1>;
    tcpc = <&ucpd1>;
	vbus = <&vbus1>;
	power-role = "sink";
	sink-pdos = <PDO_FIXED(5000, 100, 0)>;
};

vbus1: vbus {
	compatible = "zephyr,usb-c-vbus-adc";
	io-channels = <&adc2 8>;
	output-ohms = <49900>;
	full-ohms = <(330000 + 49900)>;
};

However, any of the above nodes make the build fail.

Thanks in advance for your help!

- Laci

  • Hi,

    I want to measure VBUS without any external circuitry

    From zephyr,usb-c-vbus-adc: "Resistance of the lower leg of the voltage divider"

    This means that you need a voltage divider, which is external circuitry.

    I do not think you will be able to measure the voltage without any external circuitry with a nRF52840.

    do I need to sacrifice one or multiple pins for this purpose?

    From what I can see, you need 1 pin to measure the voltage. I suggest that you test the sample with a DK to be sure.

    CONFIG_DT_HAS_ZEPHYR_USB_C_VBUS_ADC_ENABLED

    This is automatically generated if you have enabled the DTS node.

    However, any of the above nodes make the build fail.

    I need a build log to be able to say what went wrong.

    Regards,
    Sigurd Hellesvik

Related