AnsweredAssumed Answered

SCI for Send Char and Receive Char

Question asked by I-Sheng Lin on Jul 19, 2009
Latest reply on Jul 20, 2009 by I-Sheng Lin

Hi,all.

 

The MCU i am using now is MCF51QE128. The dev board is DEMOQE.

 

What I'm trying now is to send the command to my Xbee from my MCU.

 

The send function has been tested and completed done. The receive function has been tried through different ways as well.

 

When the command(+++) send to my Xbee, the Xbee will reply "OK" through serial port.

 

I was trying to get the "OK" but unfortunately, it never got before.

 

I am pretty sure the Xbee reply a OK already since the LED on the Xbee dev board is blinking while replies a "OK".

 

There may be some registers I set wrong to cause I can not get the "OK".

 

Below is my send and receive function.

 

Hope someone who is experienced can help me to deal with this problem.

 

I try to figure out what's going out 2 weeks already but still nothing discovered.

 

----------------------------------------------------Send function--------------------------- 

void SendMsg(char msg[]) {
  byte i=0;
  char nxt_char;
 
  PTCD = 0x00;
  SCI1C2 = 0x08;    // enable Tx
  SCI1C2_TCIE =1;   //Transmission complete interrupt enable
  nxt_char = msg[i++];
  while(nxt_char != 0x00) {
    while(!SCI1S1_TDRE){}
    SCI1D = (byte) nxt_char; // 2nd half of TDRE clear procedure
    nxt_char = msg[i++];
  } //end while
} //end SendMsg 

 

----------------------------Receive function--This function is put into main function already----------------------------------

void SCI_init(){
  
  SCI1C2_RIE = 1;    //set rx interrupt enable
  SCI1C2_RE = 1;    // enable Rx
 
}

 

------------------------I use Rx ISR to start my Receive function------------------

interrupt VectorNumber_Vsci1rx void SCIrx_ISR(void){
 
  SendMsg("Rx is working now!!");       //set up the led to test if the rx is triggered.\
  PTCDD=0x02;   //set up the led to test if the Rx is triggered.
  char rec_char[3];
  static int pos = 0; 

  if (SCI1S1_RDRF)
  {
    rec_char[pos] = (char)SCI1D;  // 2nd half of RDRF clear procedure
    pos++;

    if ( pos == 3)
    {
       if ( rec_char[0] == 'O'  && rec_char[1] == 'K' && rec_char[2] == '\n') {
      
       SendMsg("You got it!!");
     
      pos =0;
       }
    
      else{
       
       SendMsg("You got wrong!!");
     
      pos = 0;
      }
   
    }
     
  }
  SCI1C2_RIE = 1;
  SCI1C2_RE = 1;    // enable Rx
}

Outcomes