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.

UART test code fails when switching from UART0 to UART1

Other Parts Discussed in Thread: MSP430F5438, MSP430F5437

Hi,

I've successfully run a modified UART code examples found at this site. It uses UART0 of my device (an MSP430F5438) and blink a LED each time a new character goes into the RX buffer. But when I try changing the code to use UART1 something happens and the LED stop blinking, can you see what I've done wrong / forgot?

#include "msp430x54x.h"

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P4DIR |= 0x0f;                        // Set P4.0-3 to output direction
  P4SEL |= 0x00;                        // I/O function selected for the pins

  P5SEL |= 0xc0;//0x30;                      // P5.6,7 USCI_A1 TXD/RXD       // P3.4,5 = USCI_A0 TXD/RXD
  UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA1CTL1 |= UCSSEL_2;                     // SMCLK
  UCA1BR0 = 6;                              // 1MHz 9600 (see User's Guide)
  UCA1BR1 = 0;                              // 1MHz 9600
  UCA1MCTL = UCBRS_0 + UCBRF_13 + UCOS16;   // Modln UCBRSx=0, UCBRFx=0,
                                            // over sampling
  UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA1IE |= UCRXIE;                         // Enable USCI_A1 RX interrupt

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
  __no_operation();                         // For debugger
}

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
  switch(__even_in_range(UCA1IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    while (!(UCA1IFG&UCTXIFG));             // USCI_A1 TX buffer ready?
    P4OUT ^= 0x04;                          // Toggle P4.1 using exclusive-OR   
    //UCA0TXBUF = UCA0RXBUF;                  // TX -> RXed character
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }
}

BR Adde

  • I've struggled some more with this and the code now looks like this:

    void Init_UART1()

      UCA1CTL0 &= ~(0x01);                      // Clear UCSYNC bit to select UART

      P5SEL &= ~(0x30);                         // I/O function selected for pins P5.5 and P5.4 (RTS and DTR)
      P5SEL |= 0xc0;                            // P5.6,7 = USCI_A0 TXD/RXD
     
      UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
      UCA1CTL1 |= UCSSEL_2;                     // SMCLK
      UCA1BR0 = 6;                              // 1MHz 9600 (see User's Guide)
      UCA1BR1 = 0;                              // 1MHz 9600
      UCA1MCTL = UCBRS_0 + UCBRF_13 + UCOS16;   // Modln UCBRSx=0, UCBRFx=0,
                                                // over sampling
     
      UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      UCA1IE |= UCRXIE + UCTXIE;                         // Enable USCI_A0 RX interrupt

      __bis_SR_register(GIE);                   // Enter LPM0, interrupts enabled
    }

    I'm trying to use the GPIO pins 5.4,5 as RTS and DTR when I communicate with the PC. I have been tooled that this is needed and I have to use a software based flow control scheme since MSP430 don't have any hardware flow control. Does anyone have any examplecode using such a scheme or have any other idea how I can proceed?

    Thank you

    Adde

     

  • I have the same problem on MSP430F5437.

    Did you found any soluation?

     

     

     

  • Actually I don't work with UART1 any more. I'm using UART0 and 2 and those work fine, probably UART1 as well, if I try it today. This is the code I'm using for UART2, can that be of any help to you?

    #ifdef UART2_ACTIVE
        case UART2:
          Uart2_RX_Buffer = (U8*)malloc( MAX_RECEIVE_BYTES * sizeof(U8) );
          Uart2_TX_Buffer = (U8*)malloc( MAX_TRANSMIT_BYTES * sizeof(U8) );

          P9SEL |= 0x30;                            // P9.4,5 = USCI_A2 TXD/RXD
          UCA2CTL1 |= UCSWRST;                      // **Put state machine in reset**
          UCA2CTL1 |= UCSSEL_2;                     // SMCLK
          UCA2CTL0 = 0;                             // 8-N-1, UART Mode
          UCA2BR0 = BRSettings.BR0Value;            // 1MHz 115200 (see User's Guide)
          UCA2BR1 = BRSettings.BR1Value;            // 1MHz 115200
          UCA2MCTL |= ( BRSettings.BRSValue << 1 );
          UCA2MCTL |= ( BRSettings.BRFValue << 4 );
          UCA2MCTL |= ( 0x01 & BRSettings.UCOS16Value );
                                                    // Modln UCBRSx=1, UCBRFx=0,
                                                    // over sampling
          UCA2CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
          UCA2IE |= UCRXIE;                         // Enable USCI_A2 RX interrupt
          break;
    #endif

    Might help to se the BRSettings type as well:

    typedef struct
    {
      U8 BR0Value;
      U8 BR1Value;
      U8 BRSValue;
      U8 BRFValue;
      U8 UCOS16Value;
    } BaudRateSettingsT;

    Tell me how it works out for you.

    /Adde

  • Thank for your reply, But the MSP430F5437 have not UARTA2.

    My setting of  UARTA1 is similar to yours.

     

    P5SEL = 0xC0;       

    UCA1CTL1 |= UCSWRST;                      

    UCA1CTL1 |= UCSSEL_2;                     // SMCLK as 4MHz

    UCA1BR0 = 0x24;                                    // 4MHz 115200

    UCA1BR1 = 0x00;                                    // 4MHz 115200

    UCA1MCTL |= UCBRS_3 + UCBRF_0;  

    UCA1CTL1 &= ~UCSWRST;           

    UCA1IE |= UCRXIE;

     

    Why the UARTA1 didn't work, it's very strange....

     

     

  • Have you used an oscilloscope to see that you actually transmit data, and verified your baudrate? 

    If I intend to use UART1 in the future and get it up and running I will send you a message.

    /Adde

  • use  _EINT();  function as a last stament in UART iniit.

    hope this will work.

     

    Regards

    Ramakrishna

**Attention** This is a public forum