2
\$\begingroup\$

I have a project generated from CubeMX for my STM32Nucleo F303K8. My IDE is SystemWorkbench.

I am using a total of 8 Analog inputs split between two ADC's

ADC1: 1, 2, 4, 12.

ADC2: 1, 2, 3, 4.

I am not sure how to properly read these. I am using DMA and the frequency in which I check the value is much slower than the scan time. But even if it wasn't, I wouldn't care if I read the same value twice.

I just want to have a continuous scan, when one finishes the next starts.

But whatever I try to do, it seems that the only way I can get continuous scans is by manually starting the ADC scans over and over in my main loop using:

HAL_ADC_Start(&hadc1);
HAL_ADC_Start(&hadc2);

or the _IT variant.

I have tried enabling continuous conversion and then starting the ADC once outside my main loop. But that just does one scan and stops there.

I thought maybe I could just use the scan complete interrupt to restart the scan when it finishes. This works when I restart only one ADC inside the interrupt. However as soon as I add the second to the callback then the system locks up. Obviously there is an interrupt not being handled somewhere.

 /**
 * @brief Callback when an ADC scan completes.
 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
    if (hadc->Instance == ADC1)
    {
        //HAL_ADC_Start_IT(&hadc1);
    }
    if (hadc->Instance == ADC2)
    {
        //HAL_ADC_Start_IT(&hadc2);
    }

}

My full code is here: Current commit refid: ef11437

https://github.com/c-herring/Sumo2017_NucleoF303/tree/ef11437f2f21d1beaa2ead0d9f5393c295cf9981

If anyone has any insight for me that would be greatly appreciated.

\$\endgroup\$
  • \$\begingroup\$ Use this with DMA HAL_ADC_Start_DMA(&hadc1, ADC_buffers.ADC1_Buffer, ADC_BUFFER_LENGTH);. \$\endgroup\$ – Bence Kaulics Sep 8 '17 at 13:47
  • 1
    \$\begingroup\$ You have to handle the appropriate DMA channel and ADC IRQs. \$\endgroup\$ – Bence Kaulics Sep 8 '17 at 13:53
  • \$\begingroup\$ @Bence Kaulics even better DMA interrupts instead of ADC ones as it assures that transfers are completed, not only the conversions \$\endgroup\$ – P__J__ Sep 8 '17 at 23:34
  • 3
    \$\begingroup\$ This is NOT a forum where you mark a thread solved. This is a question and answer site where you ask a question and people post answers. Since you found the solution yourself, you can post an answer and accept it so that the question is properly completed. \$\endgroup\$ – JRE Sep 9 '17 at 13:39
  • \$\begingroup\$ Don't edit the solution into the question, remove that and post an answer, and then after the waiting period for self-answers, accept it. This is the only way to mark a question as resolved in the stack exchange system. \$\endgroup\$ – Chris Stratton Sep 9 '17 at 15:09
2
\$\begingroup\$

I have managed to find a solution. Although as PeterJ_01 mentions, this may just be a workaround to a much larger problem.

The cause of my problem appears to be that I had the cycle time set to 61.5 cycles per channel. Which seems to be too fast when doing 8 conversions. My suspicion was that I was saturating the µC. Which is why restarting only one ADC in the callback would work. but not both. But I guess it is something deeper than that.

I have upped the cycle time to 601.5 cycles and it all works!

Also, I realize that I do not need ADC interrupts enabled to restart the conversion. Since the DMA automatically attaches HAL_ADC_ConvCpltCallback to the conversion complete DMA interrupt.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.