SCI baud rate,  PLL ?

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

SCI baud rate,  PLL ?

跳至解决方案
1,512 次查看
MO_84
Contributor III

Hello again,

 

I'm able to send a receive the correct data using the below Initialization registers. My clock frequency is 4MHz and I'm using HCS12

void OpenSCI(void){    SCI0BDL=0x68; /* 4000000/16/2400==>2400 bps 4MHz is Bus clock for crystal freq of 8MHz*/               SCI0BDH=0x00; /* 0x00 ==>0x0068 is divisor to produce 2400 bps */    SCI0CR2=0x2C; /* enable SCI, enable receive interrupt */}

 

 

 

The problem starts when I change the clock from 4MHz to 24MHz using PLL code below and try to send data:

 

void Set_Clock(void){    CLKSEL &= 0x7F;    PLLCTL |= 0x40;    SYNR  = 0x05;    REFDV = 0x01;    while(!(0x08 & CRGFLG));    CLKSEL |= 0x80;} void OpenSCI(void){    SCI0BDL=0x71; /* 24000000/16/2400==>2400 bps 24MHz is Bus clock for crystal freq of 48MHz*/                 SCI0BDH=0x02; /* 0x00,0x0271 is divisor to produce 2400 bps */    SCI0CR2=0x2C; /* enable SCI, enable receive interrupt */}

 I can still send and receive data but its sending strange characters.

I think there's a problem with the baud rate. I have gone over the math and initialization and it looks correct.

 

Any ideas as to why I'm getting random characters ??

标签 (1)
0 项奖励
1 解答
691 次查看
Sten
Contributor IV

As kef says, the recommended way is to write SCIBD as a word, but if you want to write it as two bytes, you must write SCIBDH first and then SCIBDL, otherways the write of SCIBDH is ignored.

 

Sten

 

在原帖中查看解决方案

0 项奖励
4 回复数
691 次查看
kef
Specialist I

Why don't you write whole SCIBD register at once, SCIBD = 0x271.

 

From baud rate register bits description:

-Writing to SCIBDH has no effect without writing to SCIBDL, since writing to SCIBDH puts the data in a
temporary location until SCIBDL is written to.

 

Or, what you write to SCIBDH is ignored until you write to SCIBDL. Looking at you code it seems that SCI module sees SCIBD=0x71, which is about 13kbps at 24MHz bus. You may check that with scope.

0 项奖励
691 次查看
MO_84
Contributor III

I'm still can't see where the problem is.

The code does what you say.

 

first it writes to SCIBDL and then to SCIBDH.

 

So I don't see how SCIBDH is engnored since it is written to after SCIBDL.

 

 

0 项奖励
692 次查看
Sten
Contributor IV

As kef says, the recommended way is to write SCIBD as a word, but if you want to write it as two bytes, you must write SCIBDH first and then SCIBDL, otherways the write of SCIBDH is ignored.

 

Sten

 

0 项奖励
691 次查看
MO_84
Contributor III

 

Ok. that fixed the problem.

 

Thanks Kef and Sten for your help.

 

Its much appreciated.

 

Mo

0 项奖励