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.

MSP430F5528: UART COMMUNICATION

Part Number: MSP430F5528


Hi,

The system is first msp430 transmits a data then in some distance receiver receives that and does the work accordingly then it transmits an acknowledge signal it received by the msp430 receiver  and it glows a status led. The code is

#include <msp430.h>

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 = 19;
      break;                             // Vector 4 - TXIFG
  default: break;
  }
}

In this first msp430 is transmitting and it is being received in other side and an acknowledge signal also coming from other side but msp430 is not receiving. Please help....

  • Hi pabel,

    You have to read the value of UCA1RXBUF to automatically clear UCRXIFG, otherwise it will need to be cleared manually. You should also not set UCTXIE unless you want to continuously send the value 19 as quickly as possible. I recommend setting UCA1TXBUF only after you have received the last character in the RXIFG case of the ISR. Make sure that the acknowledge signal is properly connected to P4.5/UCA1RXD.

    Regards,
    Ryan
  • Hi,

    I need to first transmit a data then wait for the acknowledge and after receiving that again transmit , it continuous. For this, how the code should be? Please give an example.

    In the previous code I started reading the UCA1RXBUF  , still there is no effect. 

     

  • Hello Pabel,

    Start by writing the first value to TXBUF before entering LPM0, then read the value of RXBUF and populate TXBUF with the next value inside of the RX ISR. TX interrupts are not necessary for your application.

    Regards,
    Ryan

**Attention** This is a public forum