2

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.

Chris
  • 81
  • 1
  • 4
  • Use this with DMA `HAL_ADC_Start_DMA(&hadc1, ADC_buffers.ADC1_Buffer, ADC_BUFFER_LENGTH);`. – Bence Kaulics Sep 08 '17 at 13:47
  • 1
    You have to handle the appropriate DMA channel and ADC IRQs. – Bence Kaulics Sep 08 '17 at 13:53
  • @Bence Kaulics even better DMA interrupts instead of ADC ones as it assures that transfers are completed, not only the conversions – 0___________ Sep 08 '17 at 23:34
  • 3
    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. – JRE Sep 09 '17 at 13:39
  • 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. – Chris Stratton Sep 09 '17 at 15:09
  • `But the cause of my problem was that I had the cycle time set to 61.5 cycles per channel. This was way to fast and was just saturating the µC.` it will definitely not saturate your uC. Problem lays somewhere else and you just fond the workaround, not the solution – 0___________ Sep 10 '17 at 12:10

1 Answers1

2

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.

Chris
  • 81
  • 1
  • 4