can not send string correctly to hyperterminal window.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

can not send string correctly to hyperterminal window.

1,733 Views
Gaoya
Contributor I

I am using EVM 8367 to learn how to program on freecale chip.

since I do not want to code with processor expert,I wrote code in C directly.

I set up a hyperterminal window on computer , bits rate 19200,  8 data bits, no parity , 1 stop bit.  then I code as follows:

//***********************************************************************************************

#include <stdio.h>

#include <stdlib.h>

 

#define     sci0br           (volatile unsigned int *)0xf280

#define     sci0ctr1        (vlatile unsigned int *)0xf281

#define     sci0ctr2        (volatile unsigned int *)0xf282

#define     sci0sr           (volatile unsigned int *)0xf283

#define     sci0dr           (volatile unsigned int *)0xf284

#define     tx                   0x08

#define     rx                   0x04

 

 

 

/* prototype */

void init_sci();

void sci_outcstr(char *t);

void setsci0(char onoff);

 

 

#pragma interrupt saveall

 

 

void init_sci()

{

      *sci0br=208;

      *sci0ctr1=0x00;

      *sci0ctr2=0x00;

}

 

void setsci0(char onoff)

{

      *sci0ctr1=onoff;

}

 

  

 

void sci_outcstr( char *t)

{

unsigned short i;

while (*t!=0)

{

while (!(*sci0sr&0x8000)) { }

  t++;

  *sci0dr=*t;

 

for (i=0; i<30000; i++) { };

 

} 

 

}

 

 

 

int main(void)

{

 

int i=0 ;

init_sci();

setsci0(tx|rx);

 

 

sci_outcstr("\nFreeScale\r");

 

for (i=0; i<30000; i++) {};

 

return(0);

}

 

//***********************************************************************

I always get some random characters in whole string  like " F**rS*cal*".

Any idea? Thank you.

Labels (1)
0 Kudos
Reply
2 Replies

1,193 Views
isionous
Contributor III

...can't seem to edit my earlier post.  Anyway, you should also make sure your main function never exits.  I would advise replacing your for-loop in main with a "while(1);".

0 Kudos
Reply

1,193 Views
isionous
Contributor III

I couldn't find a good datasheet that discusses the SCI registers in detail, but if you link me to one, I might be able to help you further.

 

One of the first things to double-check your calculations to reach a SCI0BR value.  Also, using a logic analyzer or oscilloscope to check the bit length of the SCI output of your microcontroller is very helpful.

 

Another thing I noticed is that your sci_outcstr function probably doesn't function like you intend it to.  The way you handle the t variable means that you'll skip the first character of the string and output the null character.  Assuming that you are using the sci0sr register correctly, you might want to change your sci_outcstr function to this:

 

 

void sci_outcstr(char *t){    while(*t)    {        while(!(sci0sr & 0x8000));        *sci0dr = *t;        t++;    }}

 

Note that the "t++;" and the "*sci0dr = *t;" are switched from your version.

 

 

 

 

 

0 Kudos
Reply