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.

MSP430F2618 UART Interrupt



I am trying to get one of the example codes from TI to work. It is related to using the UART interrupt, and having the ISR echo back a character through the UART RX interrupt line.

I wanted to test to see if the setup was correct, but when I run and debug it, it seems like the ISR is not firing. I modified the code by adding a transmit 0x41 character so the ISR will trigger, but when I put a breakpoint in the ISR, the program does not stop...

I have not really worked with MSP430 before and I am not too familiar with the syntax of checking the flags to see if the transmission can be performed or not

BTW, I am using both Code Composer Studios and IAR and it both doesn't work.

 

Can anyone help?!?!

 

//******************************************************************************

//   MSP430x26x Demo - USCI_A0, 115200 UART Echo ISR, DCO SMCLK

//

//   Description: Echo a received character, RX ISR used. Normal mode is LPM0.

//   USCI_A0 RX interrupt triggers TX Echo.

//   Baud rate divider with 1MHz = 1MHz/115200 = ~8.7

//   ACLK = n/a, MCLK = SMCLK = CALxxx_1MHZ = 1MHz

//

//             MSP430F261x/241x

//             -----------------

//         /|\|              XIN|-

//          | |                 |

//          --|RST          XOUT|-

//            |                 |

//            |     P3.4/UCA0TXD|------------>

//            |                 | 115200 - 8N1

//            |     P3.5/UCA0RXD|<------------

//

//   B. Nisarga

//   Texas Instruments Inc.

//   September 2007

//   Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A

//******************************************************************************

#include  "msp430x26x.h"

 

void main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                     

  {  

    while(1);                               // If calibration constants erased

                                            // do not load, trap CPU!!

  }    

  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO

  DCOCTL = CALDCO_1MHZ; 

  P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD

  UCA0CTL1 |= UCSSEL_2;                     // SMCLK

  UCA0BR0 = 8;                              // 1MHz 115200

  UCA0BR1 = 0;                              // 1MHz 115200

  UCA0MCTL = UCBRS2 + UCBRS0;               // Modulation UCBRSx = 5

  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

  IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

 

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled

 

while(1)

{

  while (!(UCA0TXIFG));

  UCA0TXBUF = 0x41; 

}

}

 

// Echo back RXed character, confirm TX buffer is ready first

#pragma vector=USCIAB0RX_VECTOR

__interrupt void USCI0RX_ISR(void)

{

  while (!(IFG2&UCA0TXIFG));                // USCI_A0 TX buffer ready?

  UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character

}

 

  • Hi dcwang3,

    How do you want to test the program? Are you connecting the UART TX-RX pin of theMSP430 directly? Basically the code after the line:

     __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled

    will be not executed in any case. The reason is that because after executing the line above, the CPU will go to low power mode. It can be re-activated, if only you clear the LPM0 bits of SR register which is pushed into the stack at the interrupt acceptance in your ISR. So if you want to execute the code in the super loop while(1), you should remove the line above. But anyway the program in the while(1) loop shall also be changed to:

    while(1)

    {

      while (!(IFG2&UCA0TXIFG));

      UCA0TXBUF = 0x41; 

    }

    I would also recommend you to take a look at the MSP430 Software Coding Techniques document (http://www.ti.com/litv/pdf/slaa294a), it would help you the get the basic understanding on how MSP430 programming is usually done.

    Hope this helps.


     



  • yeah I had the RX -TX lines of the controller directly connected to each other (as a loopback test)

    I guess I missed that, I was under the impression that LMP0 was all clocks enabled, but I guess that wasn't the case. So would I just take out the LMPo_bits command and leave the GIE command in the bis_SR_Register function?

    If I wanted to go into low power mode, would I enter it right after the UCA0TXBUF = 0x41, then once it is transmitted to the RX line, the uC will be woken up and the LMP0 bits can be cleared within the ISR to go back to normal mode?

     

    Thanks for the help

  • Hi dcwang3,

    yes, setting the LPM0 bits will basically turn the CPU off by disabling MCLK. And yes, ince the CPU goes to LP mode you can reactivate the CPU in ISR by clearing the LPM0 bits of the SR register which is pushed inside the stack at interrupt acceptance (see 2xx Family US chapter 2.2.3 and 2.2.4 for more information) . The easiest way to do this is by using the following intrinsic line:

      __bic_SR_register_on_exit(LPM0_bits);

    I hope this helps.

     

  • thanks it did!!!

**Attention** This is a public forum