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.

CCS/MSP430F5529: Problem in communication with UART while using timer with interrupt

Part Number: MSP430F5529
Other Parts Discussed in Thread: MSP430F5329

Tool/software: Code Composer Studio

Hello Sir/Mam,

I have two TI controllers one is MSP430f5529 and other is MSP430f5329.

I setup UART  interrupt communication protocol for communicating each other(full duplex communication).

Now the 5529 code part also have a timer setup with interrupt 

The problem is my timer is running in background and in the while part i send some data to other msp5329 for a certain condition.

when my program reaches to send part of uart its automatically goes to UART interrupt part. and after that return to send function

i dont know how to solve this strange problem because timer have different interrupt and uart has different.

Here is my code of MSP430F5529.  

void main()
{
Timer();
uartInit();
__enable_interrupt();
while(1)
{
//certain condition
send_uart("abcdef");
}
}

void Timer()
{
  TA0CCTL0 = CCIE;                          // CCR0 interrupt enabled
  TA0CCR0 = 1850;
  TA0CTL = TASSEL_2 + MC_1 + TACLR;
}
/////////////////////timer interrupt part////////////////////////////////////////////////////////
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
 #elif defined(__GNUC__)
 void __attribute__ ((interrupt(TIMER1_A0_VECTOR))) TIMER1_A0_ISR (void)
 #else
 #error Compiler not supported!
 #endif
{
    count++;
    P2OUT |= 0x07;
    P1OUT |= 0xF8;
    AllCondition();
    __bis_SR_register_on_exit(GIE);
}

void uartInit()
{
    P4SEL |= (BIT4+BIT5);

    P4DIR |= BIT6;                     //clock for send data
    P4REN |= BIT6;
    P4OUT &=~ BIT6;

    UCA1CTL1|=UCSWRST;
    UCA1CTL1|=UCSSEL_2;
    UCA1BR0 =9;
    UCA1BR1 =0;
    UCA1CTL1 &=~UCSWRST;
    UCA1IE |=UCRXIE;
 //   __bis_SR_register(GIE);
    __no_operation();
}

void send_uart(char *addr)
{  P4OUT|=BIT6;
    unsigned int i;
    unsigned int size =strlen(addr);
    for(i=0;i<size;i++)
    {
    while(!(UCA1IFG & UCTXIFG));
    UCA1TXBUF = addr[i];
    }
    P4OUT&=~BIT6;
}

//////////////////////////////////UART INTERRUPT///////////////////////////////////////
#if defined(__TI_COMPILER_VERSION__)|| defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void__attribute__((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error compiler not supported!
#endif
{

switch(__even_in_range(UCA1IV,4))
{
case 0:break;
case 2:
    //while(!(UCA1IFG & UCTXIFG));
    *received = UCA1RXBUF;
    *received++;

break;
case 4:break;
default:break;
}
}

  •     while(!(UCA0IFG & UCTXIFG));

        UCA0TXBUF = addr[i];

    This is using UCA0, but I only see initialization for UCA1. Did you intend to use both UARTs?

    -------------------------------------

        AllCondition();

    What does this function do? Does it take longer than 90 microseconds to run?

    -------------------------------------

        __bis_SR_register_on_exit(GIE);

    This is enabling interrupts in main(), which is superfluous (since main() already did a __enable_interrupt()) and potentially hazardous. I suggest you remove this line.

  • In send_uart() what is the purpose of P4OUT&=~BIT6;?

    This will reset that output pin while data is being transmitted. If it must stay high until data is finished sending, enable RS485 transmitter for example, then you need to wait till all of the data is clocked out. Currently there are two bytes in process. The byte in the transmit shift register and the byte in the transmit hold register.

  • 1. Sorry for my silly Mistake its 

        while(!(UCA1IFG & UCTXIFG));

        UCA1TXBUF = addr[i];

    i corrected in the post also, i only use a single uart Module UCA1.

    2. >     AllCondition();

    In this function I toggle 8 port pins  using a counter (i.e count==1 pin1, count==2 pin2,..... till count==8 pin8) on every interrupt count increase to 1 alternate one by one. and its does not take more than 90 microseconds.

    3.>     __bis_SR_register_on_exit(GIE);

    I use this line because whenever a interrupt comes one of eight pin get toggle and i read the status of pin for future purpose, when this statement execute its return to main while(1).

    if i did not use this line then my program traps in timer ISR and not going to main while(1) 

  • After fixing the UCA0 reference(s), what does your symptom look like now?

  • Hi mohit,

    I haven’t heard from you for seven days, so I’m assuming you were able to resolve your issue. If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information. If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.

    Best Regards,

    Johnson

**Attention** This is a public forum