Part Number:MSP430F5529
Hello,
I am trying to send the character 'r' (0x72) from one msp430f5529 launchpad to other using UART. The other launchpad detects 'r' (0x72) and glows the LED at p1.0.
This is my Code for both the launchpads.
Transmitter
#include<msp430.h>
intmain(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
while(1){
while(UCA0STAT & UCBUSY);
UCA0TXBUF = 0x72;
}
__no_operation(); // For Debugge
}
Receiver
#include<msp430.h>
unsignedint k;
intmain(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= BIT3+BIT4; // P3.3,4 = USCI_A0 TXD/RXD
WDTCTL = WDTPW+WDTHOLD; // Stop WDT
P1DIR |= BIT0; // P1.0 set as output
P1OUT &= ~BIT0;
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
__interruptvoidUSCI_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:
k = UCA0RXBUF; // TX -> RXed character
if (k == 0x72)
P1OUT |= BIT0;
break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}
I connected P3.3, P3.4 of tx launchpad to P3.4, P3.3 of rx launchpad resp. I am receiving garbage values in UCA0RXBUF and the led is not glowing.
Any mistakes I have done in the Code?