Cannot communicate!

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

Cannot communicate!

1,427 Views
Halom
Contributor I
Hi,
 I am wrting a C program that is supposed to establish communication between the PC (via hyperterminal) and the MC9S12C32 microcontroller.

 A part of the program should do the following:
1. Set up an ASCII message as data: • The message is: “wait for character”
2. Write the message to the screen.
3. Wait approximately 1 second with wait_sec() function.
4. Check to see if there is an input character waiting to be read. If not, loop back to b. above.
- If the character is  “n”, call Message() to read in a new message.

My code prints the message every second, but when i press "n" on the keyboard, it does not stop but continues to display the message. I believe it should stop if the the keyboard is "n".
I really dont see where the problem is.
Code:
void main(void)
{
  /* put your own code here */
  char inData[]="Wait for character";
  char input;
  int length;
  int flag;
 
  InitSci(B9600);//baudrate =9600
 
 
  flag=IntStatusSci();
 
  while (flag==0){//print message every second
     message_out(inData);
     DelayHalfSec();
     }
  input=GetSci();//get inputted character
        if(input == 'n')
        length=Message(inData,sizeof(inData));  /*read the message*/
...
}


 My initialization for the SCI  and my status finction are done like this:
Code:
void InitSci(unsigned int rate){
  SCIBDH=0;
 
  switch(rate){     /* br=MCLK/(16*baudRate)*/
    case B110/*110*/   : SCIBDL=4545  ;break;
    case B150/*150*/   : SCIBDL=3333  ;break;
    case B300/*300*/   : SCIBDL=1667   ;break;
    case B600/*600*/   : SCIBDL=833   ;break;
    case B1200/*1200*/ : SCIBDL=417   ;break;
    case B2400/*2400*/ : SCIBDL=208   ;break;
    case B4800/*4800*/ : SCIBDL=104    ;break;
    case B9600/*9600*/ : SCIBDL=52    ;break;
    case B19200/*19200*/: SCIBDL=26    ;break;
    case B38400/*38400*/: SCIBDL=13     ;break;
  }
 
  SCICR1=0;/* PE=0, no parity*/
 
  SCICR2=0x0C;/*TE=1, enable transmitter and RE=1, enable receiver*/
}

/********************
/*Status function*/
int IntStatusSci(void){
  return(SCISR1 & 0x20);//0x020->RDRF bit
}

 Maybe the problem is else but I think it is my IntStatusSCI(). but I am not sure.
please can someone help me?
Thank you
 





Message Edited by Halom on 2008-03-25 12:19 AM
Labels (1)
0 Kudos
1 Reply

205 Views
stanish
NXP Employee
NXP Employee
I guess the problem may be related to the fact the flag variable is not updated within while loop.
I assume you don't check the SCI status within message_out() or DelayHlafSec() functions. The status register is tested just once before first delay and later there is no chance to exit the loop.
I'd suggest you to use rather:
 while (!IntStatusSci()){//print message every second
     message_out(inData);
     DelayHalfSec();
 }

0 Kudos