我的MCU采用的是16M的晶振。经过PLL过后变为48M。而BUSCLK应该是PLLCLK的一半为24M
PLL代码:
PLLCTL = 0B10000001; //CME=1,PLLON=0,FM1=0,FM2=0,FSTWKP=0,PRE=0,PCE=0,SCME=1
CLKSEL = 0B00000011; //PLLSEL=0,PSTP=0,PLLWAI=0,RTIWAI=1,COPWAI=1
SYNR = 0xC2; //Set the multiplier register
REFDV = 0xC0; //Set the divider register
POSTDIV = 0x00; //Set the post divider register
PLLCTL |= PLLCTL_PLLON_MASK; //Enable the Phase Lock Loop
//Wait till the PLL VCO is within tolerance
while((CRG** & CRG**_LOCK_MASK) == 0);
CLKSEL |= CLKSEL_PLLSEL_MASK; //system clocks are derived from PLLCLK
BUSCLK应该为PLLCLK的一半,所以串口初始化的代码为:
PORTC_PC7 = 0; //初始化位接收状态
DDRC_DDRC7 = 1;
PTLRR_PTLRR6 = 0;
SCI6CR1 = 0x00;
SCI6CR2 = 0x00;
SCI6BDH |= (((24000000 >> 4) / 9600) >> 8) & 0x1F;;//24M/16/312=9600
SCI6BDL = (((24000000 >> 4) / 9600) & 0xFF);;
SCI6CR1 = 0x00;
SCI6CR2 = 0x2C;
//SCI6CR2 = SCI6CR2_RE_MASK //enable receive
// | SCI6CR2_RIE_MASK //enable interrupt
// | SCI6CR2_TE_MASK; //enable transmit
串口波特率设置为9600。
问题出在发送和接收上,不论发送还是接收数据都不对。比如发送0x66 电脑串口助手接收到的是0X26。个人感觉上是波特率不对,但是手头没有示波器也没有逻辑分析仪,代码没看出问题到底出在什么地方。第一次接触飞思卡尔,求教高手解答。 |