This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F149: UART can 't quit when device did not connect

Part Number: MSP430F149

hi, i need your help, now i'm working on msp430f149 project, and my msp430f149 will connect another device via UART, what i want to do is LCD displays "please connect device firstly" if the device did not connect when msp430f149 send data via UART. i used a timer to check, if UART device has not response in 5s, timer will set a flag, and msp430f149 will quit UART process and display "please connect device firstly", but right now, the UART process always hang on if the device did not connect. my code as below.

#pragma vector=TIMERB1_VECTOR  
__interrupt void Timer_B1 (void)
{
    switch(__even_in_range(TBIV,2))
    {
    case 2:
      {
            uarterror=1;
            TBCCTL1 &= ~CCIE;
          break;
      }
    default: break;
      
    }
}

void rs232_fn(uchar command,uchar length,uchar *ptr)
{
    uchar i,temp,checksum;
    
    //5S waiting for UART response
    TBCTL |= TBCLR;
    TBCTL = TBSSEL_1 + ID_3 + MC_1;            //clock from ACLK, and devided by 8, 32.768khz/8=4096Hz,
    TBCCTL1 = CCIE;
    IE1 &= ~URXIE0;            //disable Rx interrupt    
    while((IFG1&UTXIFG0)==0)         
    {
        if(uarterror)
            break;    
    }
    if(uarterror)
    {
        uarterror=0;
        IE1|=URXIE0;              
        page =200;
        DisplayDesk(page);    //display "please connect device firstly"
    }    
    else
    {

...

     }

}

  • Hi Jian,

    Can you point out what line of code your program hangs on?

    I see that you are using the TimerB Capture Compare register 1 (CCR1) for your timeout functionality but you never populate the value of the CCR1 register. Is this done elsewhere in your code?

    I also don't understand this portion of your code:

    while((IFG1&UTXIFG0)==0)          
    {
        if(uarterror)
            break;    
    }

    You're polling the UART transmit interrupt flag but you never place any data in the UART TX buffer. Also, this flag would not change value if a device were connected to the UART interface because it only signals that the UART TX buffer is empty. I recommend reading through Chapter 13 of the MSP430x1xx Family User's Guide to better understand the purpose of the UART interrupt flags. 

    Finally, I recommend looking into the Timer and UART examples available for download here: MSP430x13x, MSP430F14x, MSP430F15x, MSP430F16x Code Examples (Rev. T)

    Best regards, 

    Caleb Overbay

  • Hi Caleb
    thank you.
    i set the CCR1 in init function.
    you are right, actually, msp430f149 UART will send all data even the device did not connection, it just can't receive response, so i need to check the URXIFG0 register. thanks again.

    jianyang

**Attention** This is a public forum