Skip to main content
RBakk.2
Associate
August 13, 2023
Solved

Unable to write to register (example ADC1->SMPR = 7)

  • August 13, 2023
  • 1 reply
  • 993 views

I am trying to use the AD converter on my Nucleo-F030R8 board. (Actually it works with the "HAL" functions, but I am trying to program on a lower level).

While debugging I am watching my struct ADC1 (Wich points at the ADC registers). I am trying to write:

ADC1->SMPR = 7; //(ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2); but when I read the value of this register in debugging mode, it still says that the value is zero.

I have included: #include "stm32f030x8.h" in the header, but it still won't let me write to this register...

It seams to be working when I first run: MX_ADC_Init();, but if I comment it away it won't work.

This topic has been closed for replies.
Best answer by waclawek.jan

ADC registers have various interlocks controlled by the "main" control bits, and this is not always well documented. \

In this case, SMPR is probably supposed to be written after you've enabled ADC clock in RCC and enabled ADC by ADEN, but did not start it by ADSTART.

JW

1 reply

waclawek.jan
waclawek.janBest answer
Super User
August 13, 2023

ADC registers have various interlocks controlled by the "main" control bits, and this is not always well documented. \

In this case, SMPR is probably supposed to be written after you've enabled ADC clock in RCC and enabled ADC by ADEN, but did not start it by ADSTART.

JW

RBakk.2
RBakk.2Author
Associate
August 14, 2023

Enabeling the ADC in the "APB peripheral clock enable register 2 (RCC_APB2ENR)" did the trick Thank you Jan. (y)