时钟配置
STATIC VOID Bsp_InitClk(VOID)
{
PJSEL0 |= PJ_LFXIN | PJ_LFOUT;/*时钟32kHz*/
FRCTL0 = FRCTLPW | NWAITS_1;/*16M以上要使用等待1*/
PM5CTL0 &= ~LOCKLPM5;/*打开时钟并且进行设置*/
CSCTL0_H = CSKEY >> 8;/*时钟解锁允许设置*/
CSCTL1 = DCOFSEL_4+DCORSEL;/*16M -铁电不能用24M只能用16M*/
CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK ;
CSCTL3 = DIVA__1 /*选择辅助时钟分频1*/\
|DIVM__1 /*选择主时钟分频1*/\
|DIVS__16;//16分频,SPI时钟 SMCLK 1M
CSCTL4 |= LFXTOFF;/*外接9<C<12.5pf*/
CSCTL4 &= ~(LFXTOFF);/*开启片外时钟晶振*/
do
{ CSCTL5 &= ~(LFXTOFFG);/* Clear XT2 fault flag */
SFRIFG1 &= ~OFIFG; }while (SFRIFG1&OFIFG);/* Test oscillator fault flag */
CSCTL0_H = 0;/*锁住时钟设置*/
}
AD部分的初始化
STATIC VOID Bsp_InitAD(VOID)
{
/* 初始化AD引脚 *///P1.0,P1.1
P1SEL1 |= P1_ADI|P1_AC2; P1SEL0 |= P1_ADI|P1_AC2;
// P1REN &=~P1_ADI;
// P1REN &=~P1_AC2;
P3SEL1 |= P3_AC1|P3_BIT1|P3_BIT2;
P3SEL0 |= P3_AC1|P3_BIT1|P3_BIT2;
//
// while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT
REFCTL0 |= REFVSEL_3; //调高后影响采样精度
REFCTL0 |= REFON;
//REFCTL0 |= REFON;//10.30
ADC12CTL0 &=~ADC12ENC;
//ADC12CTL0 = ADC12ON+ADC12SHT0_8+ADC12MSC;
ADC12CTL1 = ADC12SHP\
|ADC12CONSEQ_1 \
|ADC12SHS_0\
|ADC12SSEL_0;
ADC12CTL2 = ADC12RES_2;
ADC12CTL3 = ADC12CSTARTADD_0|ADC12TCMAP;
//电流 A0 ADC12MCTL0 = ADC12VRSEL_1\
|ADC12INCH_0;
//电压AC2 A1
ADC12MCTL1 = ADC12VRSEL_1\
|ADC12INCH_1;
//电压AC1 A12
ADC12MCTL2 = ADC12VRSEL_1\
|ADC12INCH_12;
//基准1.25 A13
ADC12MCTL3 = ADC12VRSEL_1\
|ADC12INCH_13;
//电池 A14
ADC12MCTL4 = ADC12VRSEL_1\
|ADC12INCH_14;
//温度
ADC12MCTL5 = ADC12VRSEL_1\
|ADC12INCH_30\
|ADC12EOS;
ADC12CTL0 = ADC12ON\
|ADC12MSC\
|ADC12ENC\
|ADC12SHT0_8;
}
灰小子:
第一次见到这种问题。有没有用示波器观察一下adc信号源?
junpeng li:
回复 灰小子:
我貌似找到解决方法了,在勘误表中有说明,以前用的自检AD出错后重启程序。在勘误表中我找到了另外一种方法,试试行不行。感觉应该可以解决。
Zhenting Liu:
回复 junpeng li:
遇到同样问题,敢问你的解决方案是什么。我在AD转换后重启AD,依然会出现正常通信情况下AD停止工作