kl25z

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

kl25z

1,287 次查看
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.

标记 (1)
0 项奖励
回复
2 回复数

1,088 次查看
yihanjiang
Contributor I

Thanks Hui_Ma, that solves the problem.

0 项奖励
回复

1,088 次查看
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!
-----------------------------------------------------------------------------------------------------------------------