ADC works for buffer =1, but not more.
Posted: Thu Jan 01, 2015 3:55 pm
As a side note: Lots of "simple" applications need to "occasionally" read an analog value. The "fancy" features of the ADC with DMA autotriggering etc etc. is all not necessary, just a "what is the voltage on the pin now" function would suffice.
I've written such a function (or copied it from somewhere...)
Why does this work for NN=1, but not for other values? What am I doing wrong? Do I need to set up a timer to trigger the ADC conversions? (As you can see from the comment: I'm currently using an STM32F030... The '072s and the new PCBs should arrive tomorrow)
P.S. In main I have a simple:
PPS: static initialization of most of grpp would be more efficient, but this way I now have easy control over all the fields.
I've written such a function (or copied it from somewhere...)
Code: Select all
// This is STM32F0xx specific!
int read_adc_naiive(uint8_t channel)
{
int i, t;
#define NN 1 // NN != 1 doesn't work (yet?)
adcsample_t samples[NN];
ADCConversionGroup grpp;
grpp.circular = FALSE;
grpp.num_channels = 1;
grpp.end_cb = NULL;
grpp.error_cb = adcerrorcallback;
grpp.cfgr1 = ADC_CFGR1_RES_12BIT;
grpp.tr = ADC_TR(0, 0);
grpp.smpr = ADC_SMPR_SMP_28P5;
grpp.chselr = 1 << channel;
adcSTM32SetCCR( ADC_CCR_TSEN | ADC_CCR_VREFEN);
adcConvert (&ADCD1, &grpp, samples, NN);
t = 0;
for (i=0;i<NN;i++)
t += samples[i];
return t;
}
Why does this work for NN=1, but not for other values? What am I doing wrong? Do I need to set up a timer to trigger the ADC conversions? (As you can see from the comment: I'm currently using an STM32F030... The '072s and the new PCBs should arrive tomorrow)
P.S. In main I have a simple:
Code: Select all
adcStart(&ADCD1, NULL);PPS: static initialization of most of grpp would be more efficient, but this way I now have easy control over all the fields.