/ {
zephyr,user {
io-channels = <&adc1 1>;
};
};
&adc1{
compatible = "st,stm32-adc";
//reg = <0x42028000 0x400>;
#address-cells = <1>;
#size-cells = <0>;
clocks = <&rcc STM32_CLOCK(AHB2, 10U)>;
st,adc-clock-source="SYNC";
st,adc-prescaler = <4>;
status = "okay";
vref-mv = <3300>;
#io-channel-cells = <1>;
resolutions = <STM32_ADC_RES(12, 0x00)>;
sampling-times = <48>;
st,adc-sequencer = "FULLY_CONFIGURABLE";
st,adc-oversampler = "OVERSAMPLER_MINIMAL";
pinctrl-names = "default";
pinctrl-0 = <&adc1_inp1_pa1 &adc1_inn1_pa0>;
// Kanal 1
channel@1 {
reg = <1>; // Definiert, dass dies ADC-Kanal 1 ist
zephyr,gain = "ADC_GAIN_1";
zephyr,reference = "ADC_REF_EXTERNAL0";
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)>;
zephyr,differential; // Differenzielle Messung aktivieren
zephyr,input-positive = <1>; // Ersetzen Sie PIN_POSITIVE durch den positiven ADC-Pin
zephyr,input-negative = <0>; // Ersetzen Sie PIN_NEGATIVE durch den negativen ADC-Pin
zephyr,resolution = <12>;
};
};
/ {
pinctrl {
adc1_pins: adc1_pins {
group0 {
pinmux = <STM32_PINMUX('A', 0, ANALOG)>,
<STM32_PINMUX('A', 1, ANALOG)>;
};
};
};
};
Code:
#if !DT_NODE_EXISTS(DT_PATH(zephyr_user)) || \
!DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
#error "No suitable devicetree overlay specified"
#endif
#define DT_SPEC_AND_COMMA(node_id, prop, idx) ADC_DT_SPEC_GET_BY_IDX(node_id, idx),
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
/* Data of ADC io-channels specified in devicetree. */
static const struct adc_dt_spec adc_channels[] = {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, DT_SPEC_AND_COMMA)
};
static const int adc_channels_count = ARRAY_SIZE(adc_channels);
#else
#error "Unsupported board."
#endif
int adc_try_1()
{
int err;
uint32_t count = 0;
uint16_t buf;
struct adc_sequence sequence = {
.buffer = &buf,
//buffer size in bytes, not number of samples
.buffer_size = sizeof(buf),
};
for (size_t i = 0U; i < ARRAY_SIZE(adc_channels); i++)
{
if (!adc_is_ready_dt(&adc_channels[i]))
{
printk("ADC controller device %s not ready\n", adc_channels[i].dev->name);
return 0;
}
else
{
printk("ADC controller device %s IS ready :D \n", adc_channels[i].dev->name);
}
err =adc_channel_setup_dt(&adc_channels[0]);
if (err < 0) {
printk("Could not setup channel #%d (%d)\n", 0, err);
return 0;
}
}
}
Do you have an idea, what is missing?
best regards
Lukas