@hfabbasi
I'm using the SDK and the initialization code in a FreeRTOS application and it is quite simple (I hardcoded in channel "0" to use ADC0_DP0/ADC0_DM0 - you should probably have a #define for the channel that you use):
EnableIRQ(ADC0POLL_ADC16_IRQn);
// ADC Initialization Code
ADC16_GetDefaultConfig(&adc0pollConfigStruct);
#ifdef BOARD_ADC_USE_ALT_VREF
adc16ConfigStruct.referenceVoltageSource = kADC16_ReferenceVoltageSourceValt;
#endif
ADC16_Init(ADC0_ADC16_BASE
, &adc0pollConfigStruct);
ADC16_EnableHardwareTrigger(ADC0_ADC16_BASE
, FALSE);
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
if (kStatus_Success != ADC16_DoAutoCalibration(ADC0_ADC16_BASE)) {
#if (2 != SDK_DEBUGCONSOLE)
PRINTF("ADCPOLL ADC16_DoAutoCalibration() Failed.\r\n");
#endif
vTaskSuspend(NULL);
}
#endif
adc0pollChannelConfigStruct.enableInterruptOnConversionCompleted = TRUE;
#if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
adc0pollChannelConfigStruct.enableDifferentialConversion = TRUE;
#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
to initiate an ADC operation:
adc0pollConversionDoneFlag = FALSE;
adc0pollChannelConfigStruct.channelNumber = 0; // For ADC0_DP0/ADC0_DM0
adc0pollChannelConfigStruct.enableDifferentialConversion = TRUE;
ADC16_SetChannelConfig(ADC0_ADC16_BASE
, ADC0POLL_TASK_CHANNEL_GROUP
, &adc0pollChannelConfigStruct);
The IRQ Handler:
void ADC0POLL_ADC16_IRQ_HANDLER_FUNC(void) {
/* Read conversion result to clear the conversion completed flag. */
adc0pollSensorValue = ADC16_GetChannelConversionValue(ADC0_ADC16_BASE
, ADC0POLL_TASK_CHANNEL_GROUP);
adc0pollConversionDoneFlag = TRUE;
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}This code is really basically the same as the SDK example applications. I'm noting that in case you are wondering where the "adc16ConfigStruct" & "adc0pollChannelConfigStruct" variable structures come from and how they are defined.
Good luck!