2024-08-26 11:02 PM
I am using 5 adc values (emg[5]) and can get the value of them.
I want to use these values in the main statement, so I assigned it.
However I can't get the value. It's always zero. (good[0] = emg[0])
Can I know what's the matter of this,,? Thanks for help!
Solved! Go to Solution.
2024-08-27 07:26 AM - edited 2024-08-27 07:26 AM
Hello @lee_daeun and welcome to the community,
First, as stated by @Andrew Neil , you need to copy paste your code using the button </> instead of posting the screenshots.
Second, as stated by @waclawek.jan ,
The DMA transfer is not starting immediately after calling HAL_ADC_Start_DMA():
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) emg, 5);
good[0] = emg[0];
So you need to use interrupt callback HAL_ADC_ConvCpltCallback() and read emg ADC buffer there.
2024-08-26 11:44 PM
HAL_ADC_Start_DMA() is asynchronous, it means, that it starts the hardware process with ADC and DMA and returns immediately, not waiting for the result. It takes time until the hardware - ADC and DMA - performs the conversions, so you can't read out the results immediately after that function was called.
DMA signals when it's finished by the Transfer Complete interrupt, the is a callback in Cube/HAL which is called at that point and may be a good point to read the results. I don't use Cube/HAL, refer to is documentation or to the examples.
JW
2024-08-27 05:42 AM
If you want to use polling mode, see here for an example:
If you want to use DMA, see here for an example:
Conversions are not complete until HAL_ADC_ConvCpltCallback is called from an interrupt.
2024-08-27 05:52 AM
Please see the Posting Tips for how to properly post source code - not as screenshots:
2024-08-27 07:26 AM - edited 2024-08-27 07:26 AM
Hello @lee_daeun and welcome to the community,
First, as stated by @Andrew Neil , you need to copy paste your code using the button </> instead of posting the screenshots.
Second, as stated by @waclawek.jan ,
The DMA transfer is not starting immediately after calling HAL_ADC_Start_DMA():
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) emg, 5);
good[0] = emg[0];
So you need to use interrupt callback HAL_ADC_ConvCpltCallback() and read emg ADC buffer there.
2024-08-27 07:37 AM
@SofLit wrote:The DMA transfer is not starting immediately after calling HAL_ADC_Start_DMA():.
It should be starting, but it won't have finished - therefore the results are not yet available.
2024-08-27 08:18 AM
Indeed, I didn't express myself well ..
2024-08-27 06:48 PM
Thanks a lot! I got an answer
2024-08-28 02:18 AM
The key learning from this is to understand the "asynchronous" key word introduced by @waclawek.jan
This is a general concept in all forms of computing - not just specific to your ADC or DMA.
The distinction between synchronous (aka "blocking") and asynchronous (aka "non-blocking") APIs:
Example - illustrating the generality:
https://www.techtarget.com/whatis/definition/synchronous-asynchronous-API
#BlockingCall #NonBlockingCall #SynchronousAPI #AsynchronousAPI