2017-03-10 04:00 AM
Hallo together,
I am using a STM32Nucleo-Board with the STM32F401RE-Controller in combination with the PLC expansion board.
I have used the Cube MX tool to generate the initialization for the peripherie constisting of one ADC Channel PA0 and
one SPI interface.
Now I want to get the ADC value inside the ADC interrupt function, leave the Callback function when I got the actual value and control the digital outputs of the PLC-expansion board via SPI.
My problem is that my program does not leave the callback function and always reads out the ADC.
I tried to use the function HAL_ADC_Stop_IT(&hadc1) in the Callback function but that did not help to solve the problem.
Can anybody tell me the way to leave the HAL_ADC_ConvCpltCallback function and return back to the code
in the while(1)-function.
You can find my code attached in text-file.
Thank you in advance.
Best regards,
Patrick
2017-03-10 05:41 PM
Hi,
I had a look, my simple method is a little naughty...
maybe you can work it a different way.
in your code:
/* USER CODE BEGIN 0 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){
U_ZK = HAL_ADC_GetValue(&hadc1);adcUpdated = true; // added this line to let the foreground know the conversion is completed
}char adcUpdated; // added this declaration here to make the Variable visible throughout the code.
int U_ZK; // added this declaration here to make the Variable visible throughout the code.
/* USER CODE END 0 */
int main(void)
{
.
.
while(1){
if(adcUpdated){
adcUpdated = false;
printf('ADC value %04x\n\r',U_ZK);
}
}
in my code, I only initialise the interrupt once.
and I never deinitialise it.
once the conversion is started the ADC results just get updated in the background
but I use DMAs, so its slightly different.
2017-03-13 05:59 AM
Hi Nick,
thanks for your reply.
My problem is that I do not leave the callback-function.
Concerning to UM1725 Interrupt mode IO operation should work as described below:
Start the ADC peripheral using HAL_ADC_Start_IT()
Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
At ADC end of conversion HAL_ADC_ConvCpltCallback() function is executed and user can add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
In case of ADC Error, HAL_ADC_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_ADC_ErrorCallback
Stop the ADC peripheral using HAL_ADC_Stop_IT()
What kind of microcontroller did you use?
Maybe it is different to the STM32F401RE...
Thank you.
Best regards,
Patrick
2017-03-13 06:15 AM
Yes, I am using the STM32F091
Are you using uV5 ?
Did you pay for the license ?
Not sure how I can pay
:(
That’s why I am stuck with the ‘091 today
I found you have to disable all breakpoints first, then it will single step, then you can insert a breakpoint ok.
You are a few weeks ahead of me…
My new terminal board is based on the STM32F767 -208
I will be initialising the SDRAM hopefully this week.
________________ Attachments : image003.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hynr&d=%2Fa%2F0X0000000bCa%2F3P.yqUfoWwWsHsyo_f6gE2OLrJFfHrId5cW67HOu11s&asPdf=falseimage004.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hynm&d=%2Fa%2F0X0000000bCb%2FhPNosv3C4cgKOGQ1e6AnulPp_YBcDLW1LvVjd9uwqM8&asPdf=false2017-03-13 10:23 AM
Hi Nick,
today I found out that I had some problems with the debugger, so the code works quite fine!
Yes I use µVision4 V5 but I also only use the freeware with the limited code size at the moment!
Thank you for your hints!
I wish you good luck with your STM32F7 :)
Best regards,
Patrick