2025-05-13 2:17 AM
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:
IIO values in /sys/bus/iio/devices/iio:device0:
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:
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
2025-05-13 5:49 AM
Hi @rtie ,
as per Reference Manual and Datasheet, differential inputs are supposed to be bias at VREF+/2 +/-10%
This could explain the bad conversion results.
Regards.