STM32F4 ADC DMA and Timer1 trigger
Hello all,
I want to take ADC reading at regular intervals based on timer 1 (used OC mode). The timer must trigger the ADC to take a reading and the ADC in turn will trigger the DMA to transfer the ADC reading to memory. To check that the timer is running I am toggling a GPIO_PIN. This pin toggles but conversion is not getting triggered.
I have enabled one OC1 output pin toggle and that is toggling. One more point is, the following call triggers one conversion.
HAL_ADC_Start_DMA (&hadc1, (uint32_t *)adc_buf,ADC_BUF_LEN);
I am missing the link to TIM1 OC1 and ADC start conversion whenever the OC1 match occurs.
Can someone help please?
Below is the ADC init code.
void MX_ADC1_Init(void)
{
__HAL_RCC_ADC1_CLK_ENABLE();
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = DISABLE; //
hadc1.Init.ContinuousConvMode = DISABLE; //
hadc1.Init.DiscontinuousConvMode = ENABLE; //
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; // Is this correct?
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1; //
hadc1.Init.DMAContinuousRequests = DISABLE; //
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_10; //ADC_CHANNEL_VBAT;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
