kl25z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

kl25z

822 Views
yihanjiang
Contributor I

I am using FRDM-KL25Z development board. I found to read multi channel ADC, I have to read it twice to get the correct data. Seems like the result register didn't get updated for the first read. The issues cannot be exposed when reading single channel.

Here is the example,

     ADC0_SC1A = ADC_SC1_ADCH(8);

     rd1 = ADC0_RA;

     while (ADC0_SC2 & ADC_SC2_ADACT_MASK);

     while(!(ADC0_SC1A & ADC_SC1_COCO_MASK));

     ADC0_SC1A = ADC_SC1_ADCH(8);

     rd1 = ADC0_RA;

     while (ADC0_SC2 & ADC_SC2_ADACT_MASK);

     while(!(ADC0_SC1A & ADC_SC1_COCO_MASK));

I have to do the same algorithm twice. Anybody else got the same issue?

Did I miss anything here?

Btw, I am using Keil uVision as IDE. Thanks.

Tags (1)
0 Kudos
Reply
2 Replies

623 Views
yihanjiang
Contributor I

Thanks Hui_Ma, that solves the problem.

0 Kudos
Reply

623 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

When you write ADC channel number to ADC0_SC1A register, there doesn't need to read ADC0_RA register following.

The COCO field in ADCx_SC1n register is the only bit that you have to check if the conversion is complete in polling mode.

You could polling that COCO bit until it is set. Then you could read ADC0_RA register to get the conversion number.

Then you could write ADC channel number to ADC0_SC1A register again to start next round ADC conversion.


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------