Problem in using SCI.....sending a string

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

Problem in using SCI.....sending a string

2,383 Views
Piete
Contributor I
Hello,

I have a problem with using SCI interface. I am able to send one character but sending a string does not work. Perhaps anyone can tell me what is wrong.
I am using hyperterminal at my PC.

Code:
#define TX  0x08
#define RX  0x04
#define RIE 0x20

void InitSCI0(void){   SCI0BDH= 0x00; // SCI Baud Rate Registers (SCIBDH and SCIBDL)   // calculating the baud rate is: SCI baud rate = SCI   // module clock / (16 x BR)   SCI0BDL= 26; // SCI Baud Rate Registers (SCIBDH and SCHBDL)   // Bit 7 6 5 4 3 2 1 0   // SBR7 SBR6 SBR5 SBR4 SBR3 SBR2 SBR1 SBR0   // 26 -> 19200 Baudrate at Bus Clock 8MHz
   SCI0CR1= 0x00; // SCI Control Register 1 (SCICR1); 8N1   SCI0CR2= 0x00; // SCI Control Register 2 (SCICR2)}void SetSCI0(char OnOff){   SCI0CR2= OnOff; // SCI Control Register 2 (SCICR2)}void PutcharSCI0(unsigned char cPut){   while( !(SCI0SR1 & 0x80) );   SCI0DRL= cPut;}void PutStSCI0(unsigned char *strPut){   while (*strPut != 0)   {      while ( !(SCI0SR1 & 0x80) );
      SCI0DRL = *strPut++;   }}InitSCI0();SetSCI0(RX|TX);PutcharSCI0('3'); <- That works, sending one character                     Hyperterminal receives the 3
PutStSCI0("Send Text"); <- That does not work
                           Hyperterminal does not receive anything
                           It stopps at this line: while(!(SCI0SR1 & 0x80));

 Has anybody an idea what could be wrong? I wonder why sending one character works but sending a string fails.

Labels (1)
0 Kudos
4 Replies

543 Views
alexod
Contributor I

Have to ask, you do have SCISR1 declared as volatile, otherwise the compiler may optimize to only read it once.  Have a look at the dissasembly. 

 

Just for grins put a timing delay of just over one byte time between each character send, see what happens.

 

Beyond that, reading the data sheet for the MC9S12C, it says that TDRE is 0 coming out of reset (non-empty) so this should stop your first character sending!  This is the opposite to the behaviour on the 08's.  I have rev 1.20 of the data sheet, I see the current on-line version still maintains that fact.  

 

If you are using Codewarrior, have you tried using the beans?  Saves all this low level stuff...

0 Kudos

543 Views
Piete
Contributor I

Hello,

 

thank you very much! It seems to work fine now. I do not know what was wrong! I started a new project to test sci and now it seems to work fine.  I really do not know what was wrong.

 

Thank you very much!

 

Best regards

0 Kudos

543 Views
Lundin
Senior Contributor IV
The code looks ok. I suspect that the problem might be the debugger destroying your status flags. SCI status flags are cleared by reading, so the debugger often clears them since it reads the memory map.

Try to run the program without the BDM attached and see if it solves anything.
0 Kudos

543 Views
Piete
Contributor I
Hello,

I tried it without the BDM but is is the same. It is possible to send one character. The terminal programm on the PC can receive the character. It is not possible to send a string.



0 Kudos