Skip to main content
Jeroen3
Senior
November 3, 2016
Question

STM32F103 Dual ADC with DMA skips channel

  • November 3, 2016
  • 2 replies
  • 690 views
Posted on November 03, 2016 at 14:38

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    2 replies

    Jeroen3
    Jeroen3Author
    Senior
    November 3, 2016
    Posted on November 03, 2016 at 16:18

    Well. What a bit of rubber duck debugging can't fix, heh...

    1. The skipped channel was caused since the ADC was written to while  ADC_CR2_CAL was on.

    Fix:

      /* Power ON */

      ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_CAL;

      ADC2->CR2 = ADC_CR2_ADON | ADC_CR2_CAL;

      /* Wait 4 ADC cycles, 24 cpu cycles */

      timeout = 24;

      while(timeout--);

      /* Auto Calibrate */

      ADC1->CR2 |= ADC_CR2_CAL;

      ADC2->CR2 |= ADC_CR2_CAL;

      while(ADC1->CR2 & ADC_CR2_CAL);

      while(ADC2->CR2 & ADC_CR2_CAL);

      // Clear all flags

      ADC1->SR = 0;

      ADC2->SR = 0;

    2. After this, an address misalignment occurred using the DMA. This was caused by setting ADC_CR2_DMA before turning on the DMA channelThis causes an inevitable DMA operation (with CAL results) when turning the DMA channel on.

    So many little things aren't in the manual...

    Tesla DeLorean
    Guru
    November 3, 2016
    Posted on November 03, 2016 at 16:53

    So many little things aren't in the manual...

     

    Somehow I suspect a manual that covered all the minutiae of the implementation would be impenetrable, and it is not as if most people read it now anyway..

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..