Thanks for your strong support!!
您好,您还是没理解我提出的问题,
我已经能够正常使用ADC模块,多数情况下能够正常运行。
问题出现在刚上电的时刻,而且是偶尔出现。
当发现ADC不能触发和转换时,读出寄存器ADC_SC1,ADC_SC2,ADC_SC3观察,发现ADC_SC1中的ADCH = 0x1F,而寄存器ADC_SC2,ADC_SC3写入正确。
也就是说只有寄存器ADC_SC1写失败,触发通道没写入ADC_SC1。在故障出现后,多次写ADC_SC1,并读出ADC_SC1观察,发现ADC_SC1中的ADCH始终为11111。
我想知道的是,为什么刚上电时会出现这种现象,且只有重新上电才可以恢复。
我使用的是软件触发模式。ADC初始化代码如下:
you still don't understand my question,
I can use the ADC module aright,and it works aright in most cases.
But in the moment of MCU power on , the problem occurs occasionally.
When the fault occurs ,the ADC cannot be triggered and converted, then read the registers ADC_SC1, ADC_SC2, ADC_SC3 and observe them, ADCH = 0x1F in ADC_SC1, and the registers ADC_SC2, ADC_SC3 are written correctly.
In other words, only register ADC_SC1 failed to write, triggering channel can not be written to ADC_SC1. After the fault occurs, write ADC_SC1 for many times, read ADC_SC1, and observe that the ADCH in ADC_SC1 is always 11111.
then it can only be restored when the power is turned on again, or the MCU be reset.
Now,What I want to know why this fault occurs when the power is just turned on,
this is the code:
//-------------------------------------------------------------------------------------------------------------------
// @brief ADC初始化
//-------------------------------------------------------------------------------------------------------------------
void adc_init(ADCn_Ch adcn_ch)
{
SIM->SCGC |= SIM_SCGC_ADC_MASK; //开启ADC时钟
ADC->APCTL1 |= 1<<adcn_ch; //使能ADC引脚
}
void adc_start(ADCn_Ch adcn_ch)
{
ADC->SC3 = (0
| ADC_SC3_ADIV(3) //分频系数8
| ADC_SC3_MODE(0x01) //分辨率10位
| ADC_SC3_ADICLK(1) //使用总线时钟2分频最为ADC得时钟源
);
ADC->SC2 = ADC_SC2_REFSEL(0); //基准电压选择
ADC->SC1 = ADC_SC1_ADCH(adcn_ch); //启动转换
}
void TaskAdc_Init(void)
{
adc_init(TIN_ADC); //ADC通道初始化
adc_start(TIN_ADC); //ADC转换开始
}
uint16 adc_get(void)
{
uint16 result;
if(!(ADC->SC1 & ADC_SC1_COCO_MASK)) return 0xFFFF; //未转换完成返回-1
result = ADC->R;
return (result & ADC_R_ADR_MASK); //返回结果
}
//////////////
TaskAdc_Init();
uint16 temp ;
temp = adc_get();
if(0xFFFF!= temp)
{
}
else
{
//set a break point here. Then the fault occurs: ADCH = 0x1F
}