braddy dru

Cannot communicate!

Discussion created by braddy dru on Mar 25, 2008
Latest reply on May 28, 2008 by stanish
 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.
void main(void)
  /* put your own code here */
  char inData[]="Wait for character";
  char input;
  int length;
  int flag;

  InitSci(B9600);//baudrate =9600


  while (flag==0){//print message every second

  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:
void InitSci(unsigned int rate){

  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