STM32 - ADC Callback not invoked
Posted: Thu Aug 01, 2019 12:08 pm
Hi to all, I'm new in the forum.
I need help using the ADCConversionGroup and ADC HAL for the STM32F303VCT microcontroller.
My target is to acquire from analog input IN10, and sample in dual mode(ADC1 master, ADC2 slave) interleaved, with a total of 140*2 sample, naturally through DMA..
I have configured the group for the ADC1, in this manner:
ADC callback function:
After config.. I call:
And in the end the ADC is invoked from:
When the ext trigger go in the function daqExtTrigger(...) and invoke adcStartConversionI(...), the callback function adcCallback(...) not is invoked.
Where is the problem, naturally, first I have enable in mcuconf.h:
Another info regarding ChibiOS, this project is created with 2.6.9 version and Eclipse LUNA.
Please, someone can help me?
Thanks in advance.
Best regards.
Francesco.
I need help using the ADCConversionGroup and ADC HAL for the STM32F303VCT microcontroller.
My target is to acquire from analog input IN10, and sample in dual mode(ADC1 master, ADC2 slave) interleaved, with a total of 140*2 sample, naturally through DMA..
I have configured the group for the ADC1, in this manner:
Code: Select all
/*
* ADC conversion group.
* Mode: single, NUM_SAMPLE=2 samples of 1 channels, interleaved, SW triggered.
* Channels: IN10
*/
static const ADCConversionGroup adcgrpcfg = {
FALSE,
NUM_CHANNELS,
adcCallback,
adcErrorCallback,
ADC_CFGR_RES_12BITS, /* CFGR */
ADC_TR(0, 4095), /* TR1 */
ADC_CCR_DELAY(7) | ADC_CCR_DUAL(7), /* CCR */
{ /* SMPR[2] */
0,
ADC_SMPR2_SMP_AN10(ADC_SMPR_SMP_1P5),
},
{ /* SQR[4] */
ADC_SQR1_SQ1_N(ADC_CHANNEL_IN10), /* SQR[0] */
0, /* SQR[1] */
0, /* SQR[2] */
0 /* SQR[3] */
},
{ /* SSMPR[2] */
0,
ADC_SMPR2_SMP_AN10(ADC_SMPR_SMP_1P5),
},
{ /* SSQR[4] */
ADC_SQR1_SQ1_N(ADC_CHANNEL_IN10),
0,
0,
0
}
};
ADC callback function:
Code: Select all
/*
* ADC streaming callback.
* la priorità dell'interrupt da trigger è più alta di quella dell'ADC
* in questo modo può partire una nuova acquisizione anche durante
* l'elaborazione di quella precedente, una volta che quella corrente è completata
*/
static void adcCallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
(void)adcp;
(void)n;
// ping pong buffer
if (buffer == samplesA){
samples = samplesB;
}
else{
samples = samplesA;
}
// riabilito il trigger ADC, da questo momento potrà partire
// un'altra acquizione sull'altro buffer, durante l'elaborazione
chSysLockFromIsr();
adcStopConversionI(&ADCD1);
extChannelEnableI(&EXTD1, 6);
chSysUnlockFromIsr();
//my handling of data in..
energyEventPush(calculateEnergy((dualAdcSample_t *)buffer));
}
After config.. I call:
Code: Select all
void daqInit(void) {
daqError = 0;
//inizializzo puntatori per la coda
eventFill = 0, eventRet = 0;
/*
* Setting up analog inputs used by the RaMonA.
*/
palSetGroupMode(GPIOF, PAL_PORT_BIT(2),
0, PAL_MODE_INPUT_ANALOG);
/*
* Activates the ADC1 driver
*/
adcStart(&ADCD1, NULL);
chThdSleepMilliseconds(500);
}And in the end the ADC is invoked from:
Code: Select all
/*
* External Trigger Interrupt.
* @brief:
* Evento di trigger per iniziare l'acquisizone
* la priorità dell'interrupt da trigger è più alta di quella dell'ADC
* in questo modo può partire una nuova acquisizione anche durante
* l'elaborazione di quella precedente
*
*/
void daqExtTrigger(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
// disabilito il trigger
chSysLockFromIsr();
//attenzione avviare prima l'ADC e poi disabilitare il trigger è un rischio calcolato
adcStartConversionI(&ADCD1, &adcgrpcfg, samples, BUF_DEPTH); //BUF_DEPTH = 140 campioni per ogni ADC
//in totale 280 campioni (dual mode)
extChannelDisableI(&EXTD1, 6);
chSysUnlockFromIsr();
}When the ext trigger go in the function daqExtTrigger(...) and invoke adcStartConversionI(...), the callback function adcCallback(...) not is invoked.
Where is the problem, naturally, first I have enable in mcuconf.h:
Code: Select all
/*
* ADC driver system settings.
*/
#define STM32_ADC_USE_ADC1 TRUE
#define STM32_ADC_USE_ADC3 TRUE
#define STM32_ADC_ADC12_DMA_PRIORITY 3
#define STM32_ADC_ADC34_DMA_PRIORITY 2
#define STM32_ADC_ADC12_IRQ_PRIORITY 5
#define STM32_ADC_ADC34_IRQ_PRIORITY 5
#define STM32_ADC_ADC12_DMA_IRQ_PRIORITY 5
#define STM32_ADC_ADC34_DMA_IRQ_PRIORITY 5
#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_ADCCK //ADC_CCR_CKMODE_AHB_DIV1
#define STM32_ADC_ADC34_CLOCK_MODE ADC_CCR_CKMODE_ADCCK //ADC_CCR_CKMODE_AHB_DIV4
#define STM32_ADC_DUAL_MODE TRUE
Another info regarding ChibiOS, this project is created with 2.6.9 version and Eclipse LUNA.
Please, someone can help me?
Thanks in advance.
Best regards.
Francesco.