DEMO9S08DZ60 UART code

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

DEMO9S08DZ60 UART code

572件の閲覧回数
pawankumar
Contributor III

Hi Friends,

 

I have purchased the DEMO board and am trying to send a char. through UART @9600bps. 8 bits, 1 stop bit, pairity : None.

 

Please see my code and help me understand my mistake. I am getting junk value at the terminal.

 

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#define led1  PTBD_PTBD3

#define led2  PTCD_PTCD5

void delay(int m)//delay in ms

{

  int i,p,j;

  for(p=0;p<m;p++)

  {

  for(i=0;i<4;i++)

  {

  for(j=0;j<1000;j++);

  }

  }

}

void main(void) {

  int s;

  s=0;

  SOPT1_COPT = 0; //Disable WDT

 

 

  /* include your code here */

  //Configure Baud rate 9600bps, 8 bit, 1 stop bit.

//MCG not altered, so, BUS_CLK =20MHz

  //9600bps

SCI1BDH=0x00;

SCI1BDL=0x82;

//invert bits

SCI1C3=SCI1C3|SCI1C3_TXINV_MASK;

//Transmission enable

SCI1C2=SCI1C2|SCI1C2_TE_MASK;

SCI1C1=0x00;

 

 

while(1)

{

while(SCI1S1_TDRE==0);

SCI1D=0x61;

//while(SCI1S1_TC==0);

delay(100);

 

}

 

 

 

 

  /* please make sure that you never leave main */

}

 

Thanks in advance for any help.

Pawan

ラベル(1)
2 返答(返信)

466件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pawan,

After i checked your code , i think there have possilbe reasons , you can try .

(1)  change  SCI1BDL=0x82;  to SCI1BDL=0x85;

(2)  Why you invert bits ? you can try do not invert to check whether can receive correct data .

//invert bits

SCI1C3=SCI1C3|SCI1C3_TXINV_MASK;

Wart your result !

Hope it helps

Alice

466件の閲覧回数
pawankumar
Contributor III

Thanks Alice,

Yes, It helped me. I had trouble in configuring the Clock mode. As soon as this was set, serial communication happened seamlessly.

And as you had said, There is no need to invert the bits.

Having the External crystal @4MHz and BUSCLK at 2MHz, my registers are :

SCI1BDH = 0x00;                  

SCI1BDH_RXEDGIE=0x01;

SCI1C2_RIE=0x01;

SCI1BDL = 0x34;                    

SCI1C2_TE = 0x01;                   

SCI1C2_RE = 0x01; 

Best Regards,

Pawan

0 件の賞賛