2017-05-02 03:07 AM
Hi
I am trying to read an adc value from a potentiometer with the following code:
uint32_t readADCServo()
{ uint32_t adcValue, adcValueDegrees; HAL_ADC_Start(&hadc1); if (HAL_ADC_PollForConversion(&hadc1, 1)!=HAL_OK) { } while ((HAL_ADC_GetState(&hadc1) & HAL_ADC_STATE_REG_EOC ) == HAL_ADC_STATE_REG_EOC) { adcValue = HAL_ADC_GetValue(&hadc1); } HAL_Delay(1); adcValueDegrees = (adcValue * 180 / 4095) -90; return adcValueDegrees; }The only value i get in adcValue is
536872088. No matter the position of the potentiometer.
Does anyone have a soluton for my problem?
#read-adc-potentiometer #adcSolved! Go to Solution.
2017-05-03 08:24 AM
My problem is fixed, I started a new program with just my adc in it and now it is working. Probably a something wrong in my other code. Thanks for the replies!
2017-05-02 03:26 AM
The only value i get in adcValue is
536872088.
How do you know that?
That number looks like a variable's address, 0x20000498
JW
2017-05-02 04:34 AM
Thanks to give details on which STM32 part number is being used for better understanding.
Usually there are examples of how to use the peripheral such as ADCs on Nucleo or Discovery BSP to inspire from.
2017-05-02 05:31 AM
In the microvision debugger in the watch window, this number is under the tab 'value' for adcValue.
2017-05-02 05:42 AM
Not sure when exactly you check the contents of
adcValue
in the debugger, but this variable is placed on the stack.As soon as you leave the '
readADCServo()
' context, it is gone ...2017-05-02 07:26 AM
I use the stm32f429I, and already checked the example programs. But they are not very useful
2017-05-02 09:56 AM
[referring to AvaTar's post]
Make adcValue global (i.e. define it outside the function). Any change in behaviour?
JW
2017-05-03 04:17 AM
I have done that. You have to make a variable global to be able to read it in the watch window.
2017-05-03 05:02 AM
Not in the toolchains I know. In proper context, the debugger shows local variables in the watch window as well.
Have you tried to check the ADC result register directly in the debugger ? This might clear the interrupt flag, though.
I don't use Cube, so I do not comment on the code.
However, Jan made a valid point IMHO - the reported value looks suspiciously like an address, rather than a value.
2017-05-03 08:24 AM
My problem is fixed, I started a new program with just my adc in it and now it is working. Probably a something wrong in my other code. Thanks for the replies!