Skip to main content
Explorer
May 13, 2025
Solved

Trouble reading differential ADC channel on STM32MP157C under Linux

  • May 13, 2025
  • 1 reply
  • 577 views

I am trying to measure voltages using the STM32MP157C's built-in ADC on channel 18 in differential mode, but keep getting wrong values. Linux kernel is 6.1.28.

Here are the relevant bits from the Linux device tree:

&pinctrl {
    adc_pins_mx: adc_mx-0 {
        pins {
            pinmux = <STM32_PINMUX('A', 4, ANALOG)>, /* ADC1_INP18 */
                     <STM32_PINMUX('A', 5, ANALOG)>; /* ADC1_INN18 */
        };
    };
};

&adc1 {
    status = "okay";
    assigned-resolution-bits = <16>;

    channel@18 {
        reg = <18>;
        diff-channels = <18 18>;
        st,min-sample-time-ns = <10000>;
    };
};


Voltmeter readings:

  • 1.71 mV between INP18 (PA4) and GND
  • 1.39 mV between INN18 (PA5) and GND
  • 0.32 mV between INP18 and INN18

IIO values in /sys/bus/iio/devices/iio:device0:

  • in_voltage-voltage_offset = -32768
  • in_voltage-voltage_scale = 0.100708007
  • in_voltage18-voltage18_raw = 37273

So that's (37273 + -32768) * 0.100708007 = ~453.69 mV instead of the expected 0.32 mV as per Voltmeter.

In single-ended mode ("diff-channels" property removed), the IIO values make more sense:

  • in_voltage_offset = 0
  • in_voltage_scale = 0.050354003
  • in_voltage18_raw = 22

Here I get (22 + 0) * 0.050354003 = ~1.11 mV, which is close enough to the 1.71 mV measured by the voltmeter.

In differential mode, it looks like the computed values are off by a factor of 1000. I am, however, unsure if the "diff-channels" value is correct.

Am I doing this wrong? Is there a bug in the ADC driver in kernel 6.1?

Thanks and best regards,
Robert

    This topic has been closed for replies.
    Best answer by PatrickF

    Hi @rtie ,

    as per Reference Manual and Datasheet, differential inputs are supposed to be bias at VREF+/2 +/-10%

    PatrickF_0-1747140411772.png

    PatrickF_1-1747140515483.png

     

    This could explain the bad conversion results.

    Regards.

    1 reply

    PatrickFAnswer
    Technical Moderator
    May 13, 2025

    Hi @rtie ,

    as per Reference Manual and Datasheet, differential inputs are supposed to be bias at VREF+/2 +/-10%

    PatrickF_0-1747140411772.png

    PatrickF_1-1747140515483.png

     

    This could explain the bad conversion results.

    Regards.

    rtieAuthor
    Explorer
    May 16, 2025

    Ah, I see. Our input signals are not centered around 1.65 V, so they are completely out of range. We'll change our hardware accordingly.

    Thank you very much!