Msp430f5528 uart programming.

Thread Starter

neeladrinath

Joined Apr 5, 2017
37
Hi,
I am trying to interface a transceiver module with msp430f5528. the code is

Code:
#include <msp430.h>
    volatile unsigned int i;
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P4SEL = BIT4+BIT5;                        // P4.4,5 = USCI_A1 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 |= UCTXIE + UCRXIE;                         // Enable USCI_A0 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
#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(UCA1IV)
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
        P4DIR |=BIT7;
        P4OUT= BIT7;

    break;
  case 4:
      UCA1TXBUF = 30;
      break;                             // Vector 4 - TXIFG
  default: break;
  }
}
This code is transmitting the data but not receiving. Please help me......
 

Mark Hughes

Joined Jun 14, 2016
409
Hi @neeladrinath ,
I've never used that MSP board, but I imagine it's similar to the others.

Look under case 2: -- you're using pin 4.7 to receive, but above, you have P4SEL = BIT4+BIT5;, indicating pin 5 is receiving. So -- where is your Rx line hooked up?
Secondly, load up a UART example to see if you're missing any other small things (maybe the pin is being held in an unknown state until you properly activate it).
Lastly, comment out your switch statement and just focus on the part that's troubling you -- one less thing to worry about.
Good luck!
Mark
 

qrb14143

Joined Mar 6, 2017
112
Admittedly, my experience in this area is limited but I would have another look at that switch statement in the interrupt service routine. Bit 0 in the interrupt flag registers is reserved such that the decimal representation of the register is always an even number. For this reason, TI usually use the switch statement combined with an "__even_in_range()" function. I have no idea if this affects the function of the code or if it merely makes it more efficient. If it affects the function of the code, it may mean that the relevant switch case is never reached. Just a thought...

Code:
#include <msp430.h>

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  P3SEL |= BIT3+BIT4;                       // P3.3,4 = USCI_A0 TXD/RXD
  UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 = 9;                              // 1MHz 115200 (see User's Guide)
  UCA0BR1 = 0;                              // 1MHz 115200
  UCA0MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 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
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCA0IV,4))
  {
  case 0:break;                             // Vector 0 - no interrupt
  case 2:                                   // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG));             // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF;                  // TX -> RXed character
    break;
  case 4:break;                             // Vector 4 - TXIFG
  default: break;
  }
}
This is one of the TI examples from the resource explorer showing how to properly configure the eUSCI module.
 
Top