ADC on M4 using polling instead of interrupt

Is there an example of the ADC use on the M4 that is made using polling instead of interrupt? Is it even possible?

I can already modified the example code to handle the interruption as:

void BOARD_ADC_HANDLER(void)
{
    ADC_ClearStatusFlag(BOARD_ADC_BASEADDR, adcStatusConvertChD);
}

However, when I disable the interruption the program halts in the following line:

voltage = ADC_GetConvertResult(BOARD_ADC_BASEADDR, adcLogicChD);

Greetings @Ilan_Figueiredo!

How’s the interrupt being configured? Would you mind sharing a sample code so we can debug this?

You can use the Private option so only Toradex staff can access this.

Handler and the code that consumes the ADC result are literally as described.

Inits are:

 /* In this example, we need to grasp ADC1 module exclusively */
RDC_SetPdapAccess(RDC, BOARD_ADC_RDC_PDAP, 3 << (BOARD_DOMAIN_ID * 2), false, false);

/* Enable ADC clock */
CCM_ControlGate(CCM, BOARD_ADC_CCM_CCGR, ccmClockNeededRunWait);

// Initialize ADC module.
ADC_Init(BOARD_ADC_BASEADDR, &adcConfig);

// Enable Convert finish interrupt on Logic Channel A to D
ADC_SetIntSigCmd(BOARD_ADC_BASEADDR, adcIntConvertChD, true);
ADC_SetIntCmd(BOARD_ADC_BASEADDR, adcIntConvertChD, true);

/* Set ADC Interrupt priority */
NVIC_SetPriority(BOARD_ADC_IRQ_NUM, 3);

/* Call core API to enable the IRQ. */
NVIC_EnableIRQ(BOARD_ADC_IRQ_NUM);
}

void ADC_iMX7_init_channel_A(void)
{
// Initialize ADC Logic Channel A module.
ADC_LogicChInit(BOARD_ADC_BASEADDR, adcLogicChA, &adcChannel_A_Config);

// Start Continuous Conversion on Logic Channel A.
ADC_SetConvertCmd(BOARD_ADC_BASEADDR, adcLogicChA, true);
}

@Ilan_Figueiredo,

Did you try disabling the convert finish interrupt on the ADC channels? You could also try disabling the ADC interrupts entirely. Your code should then poll the ADC, with ADC_GetConvertResult() being a blocking call.

Hi @Ilan_Figueiredo ,

Did your ADC test program work as expected when interrupts was enabled?
At your first code snippet you are reading channel D

voltage = ADC_GetConvertResult(BOARD_ADC_BASEADDR, adcLogicChD);

but at the second snippet you init channel A

Also the ADC_GetConvertResult function is not blocking. It just read and return ADC register. You can either have an assert if you are using incorrect channel or it can crush.

Do you have Linux running on A cores while you run you M4 code?