STM32F080 ADC only converts once on Timer trigger
Posted: Sun Oct 19, 2014 11:20 pm
I am trying to get ADC work on hardware triggers since I am going to use it on some time critical applications. Now I am testing trigger using TIM3_TRGO, but the ADC only converts once. I cannot find where the problem is. The following are relavent code for ADC and TIM3 initialize:
The idea of these code is to start the timer, then turn on the master mode trigger event from timer update, and configure ADC1 to use that event to initiate conversion.
In main(), I just call vTIM3Config(), vADCConfig(), vTIM3Start(), vADCStart() in sequence and do infinite loop. In serial monitor, I found that ADC interrupt only enters once. However, the LED that is toggled in timer interrupt is flashing, so probably there is nothing wrong about timers.
Code: Select all
static ADCConversionGroup xADCConfig = {
/* Circular */
FALSE,
/* 2, /\* Current Sense, Force Sense *\/ */
/* Test, PA7/ADC_IN7 */
1,
/* Callback */
cbADCDSP,
/* Error Callback */
cbADCError,
/* CFGR1 */
ADC_CFGR1_EXTEN_0
| ADC_CFGR1_EXTSEL_1
| ADC_CFGR1_EXTSEL_0
| ADC_CFGR1_RES_12BIT,
/* TR */
0,
/* SMPR */
ADC_SMPR_SMP_1P5,
/* ADC_SMPR_SMP_239P5, */
ADC_CHANNELS
};
adcsample_t* vADCConfig(void) {
adcObjectInit(&ADCD1);
adcStart(&ADCD1, NULL);
return adc_samples;
}
void vADCStart(void) {
/* Test */
palSetGroupMode(GPIOA, PAL_PORT_BIT(7),
0, PAL_MODE_INPUT_ANALOG);
adcStartConversion(&ADCD1, &xADCConfig, adc_samples, ADC_BUF_DEPTH);
}
void cbADCDSP(ADCDriver* adcp, adcsample_t *buffer, size_t n) {
(void) adcp;
(void) n;
/* chprintf((BaseSequentialStream*)&SD1, "ADC: %d\r\n", *buffer); */
chprintf(&SD1, "ADC\r\n");
}
static const GPTConfig xTIM3Config = {
/* Frequency */
50000,
/* Callback */
cbTIM3,
/* Dier */
TIM_DIER_TIE
| TIM_DIER_UIE
};
void vTIM3Config(void) {
gptObjectInit(&GPTD3);
gptStart(&GPTD3, &xTIM3Config);
/* TRGO Event */
GPTD3.tim->CR2 &= ~TIM_CR2_MMS;
GPTD3.tim->CR2 |= TIM_CR2_MMS_1;
}
void vTIM3Start(void) {
gptStartContinuous(&GPTD3, 25000);
}
The idea of these code is to start the timer, then turn on the master mode trigger event from timer update, and configure ADC1 to use that event to initiate conversion.
In main(), I just call vTIM3Config(), vADCConfig(), vTIM3Start(), vADCStart() in sequence and do infinite loop. In serial monitor, I found that ADC interrupt only enters once. However, the LED that is toggled in timer interrupt is flashing, so probably there is nothing wrong about timers.