Using Keil + S32K144 sdk pack for keil , configure PTC15/ADC0_SE13/FTM1_CH3/TRGMUX_IN8 PIN as adc input source.
Software interrupt trigger was configured, Here is my question:When software trigger called(adc_start_convert), The unexpected interrupt was trigger. It confused me: Isn't interrupt function called when adc conversion completed?
Initialization:
{
...
PCC->PCCn[PCC_ADC0_INDEX] &= ~PCC_PCCn_CGC_MASK;
PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_PCS(6); /* PCS=6: 80MHZ */
PCC->PCCn[PCC_ADC0_INDEX] |= PCC_PCCn_CGC_MASK;
ADC0->CFG1 = ADC_CFG1_ADIV(2) | /* ADIV=2:=40MHZ */
ADC_CFG1_MODE(1) | /* MODE=1: 12 bits ADC */
ADC_CFG1_ADICLK(0); /* ADICLK=0: use default pcc clock */
ADC0->SC1[0] = ADC_SC1_AIEN_MASK | /* AIEN=1: enable interrupt trigger */
ADC_SC1_ADCH(13); /* ADCH=13: use channel 13 */
ADC0->SC2 |= ADC_SC2_ADTRG(0); /* ADTRG=0: enable software trigger */
ADC0->SC3 = 0;
S32_NVIC->ICPR[ADC0_IRQn >> 5] = 1 << (ADC0_IRQn % 32); /* register ADC0 interrupt */
S32_NVIC->ISER[ADC0_IRQn >> 5] = 1 << (ADC0_IRQn % 32); /* enable ADC0 interrupt */
S32_NVIC->IP[ADC0_IRQn] = 0x0b;
adc_start_convert(13);
...
}
void
adc_start_convert(uint16_t adcChan)
{
ADC0->SC1[0] &= ~ADC_SC1_ADCH_MASK; /* Clear prior ADCH bits */
ADC0->SC1[0] = ADC_SC1_AIEN_MASK |
ADC_SC1_ADCH(adcChan);
}
void
ADC0_IRQHandler(void)
{
...
}
Hi
At the moment that you enabled the ADC interruption, you already have selected the channel. When ADC software trigger is configured, the conversion starts at the moment that the channel has been selected.
ADC0->SC1[0] = ADC_SC1_AIEN_MASK | /* AIEN=1: enable interrupt trigger */
ADC_SC1_ADCH(13); /* ADCH=13: use channel 13 */
ADC0->SC2 |= ADC_SC2_ADTRG(0); /* ADTRG=0: enable software trigger */
Best regards
Jorge Alcala