Hi, I am working with the SAR ADC on the S32K3 series microcontroller with ADC_Sar_Ip Library, I am going for non autosar based codes. I want to read a value from a specific ADC channel, and here’s the code snippet I have written so far:
uint16_t ADC_Get_Value(uint32 adc_Instance_u32,uint32 channel_Idx_u32) {
uint16_t data;
Adc_Sar_Ip_StartConversion(adc_Instance_u32, ADC_SAR_IP_CONV_CHAIN_NORMAL);
while (Adc_Sar_Ip_GetStatusFlags(adc_Instance_u32) != 35);
data = Adc_Sar_Ip_GetConvData(adc_Instance_u32, channel_Idx_u32);
return data;
}
I noticed that the NXP SAR ADC IP driver provides an API to start conversion (Adc_Sar_Ip_StartConversion), but I could not find an API specifically for checking the end of conversion.
Experimentally, I observed that the status flags returned by Adc_Sar_Ip_GetStatusFlags reach 32 when the conversion is complete, so I used this value in my while loop. Using this method works for me, but I am unsure if this is the correct or recommended way to detect conversion completion.
My questions are:
Is there an official API in the S32K3 SAR ADC driver to check for end-of-conversion?
Why does polling Adc_Sar_Ip_GetStatusFlags until the value becomes 32 work? Is this behavior guaranteed, or is it dependent on the current driver version?
If there is no API, what is the recommended way to handle ADC conversion completion: polling the status flags, using interrupts, or adding delays?