This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

TripleMode ADC with DMA-Access

Hello everyone!
I've just picked up a STM32F446 and am currently learning to program it. To be honest: I'm struggling quite hard (coming from very simple processors like the PIC16 - the most advanced I've ever used was a MSP430).
So, here's the thing: For my current project I need to sample 9 analog values every 2 us. My first attempt was with single mode, but that turned out to be too slow. Now I'm trying to get it to work with TripleMode and DMA, which I have failed miserably until now.
The following code immediately produces an overrun on the ADC and the array that should hold the results of the conversion only contains 0x04A8.
What am I missing here? I'm thankful for any kind of help!

/* Private variables ---------------------------------------------------------*/
uint16_t ADCTripleConvertedValue[9];

/* Function Prototypes - System Setup ----------------------------------------*/
void System_Init(void);
void Init_ADCs(void);
void Init_Timer_5(void);

/*-------------- Int Main ----------------------------------------------------*/
int main(void)
{
        System_Init();                                                                                                                                          /* Setup GPIO-Pins, Timers, UART, etc */

        for (int i=0;i<9;i++)
    {
        ADCTripleConvertedValue[i]=i;
    }

        while (1)
        {
                ADC_SoftwareStartConv(ADC1);

                for(uint32_t i = 0; i < 0xFFFF; i++)
        }
}


/*-------------- Setup - functions -------------------------------------------*/
void System_Init()
{
        /* Enable peripheral clocks */
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

        Init_ADCs();
        Init_Timer_5();
}

void Init_Timer_5 ()                            /* ADC-Timer */
{
        TIM_TimeBaseInitTypeDef Timer_Struct;

        Timer_Struct.TIM_Prescaler = 9-1;                                                       /* Runs at 10 MHz */
        Timer_Struct.TIM_Period = 200000;                                                       /* 20 ms */
        Timer_Struct.TIM_CounterMode = TIM_CounterMode_Up;
        Timer_Struct.TIM_ClockDivision = TIM_CKD_DIV1;                          /* No clock division, only prescaler */

        TIM_TimeBaseInit(TIM5, &Timer_Struct);

        TIM_SelectOutputTrigger(TIM5, TIM_TRGOSource_Update);           /* ADC_ExternalTrigConv_T2_TRGO */

        TIM_Cmd(TIM5,ENABLE);
}

Rest of the code in the next post.

Parents Reply Children
No data