Hi guys,
I've been working on a UART link between an MSP430G2553 and a CC2541. I've managed to get the CC2541 to send over a byte, repeated over and over at a baud rate of 115,200
I've also managed to receive and echo the received byte on the MSP430 end, and confirmed that the value I am sending is in fact what is read on the Rx and transmitted on the Tx pins of the MSP430, using an oscilloscope to check the bits (I read 0b01000010, which is 66 in decimal, what I was trying to send).
The issue I'm having is that I can't seem to get an LED on my launchpad (which has the MSP430G2553) to light based on a conditional if statement (see below). The LED seems to light regardless of what value I set UCA0RXBUF equal to. In other words, it always lights up.
I've tried writing the if statement in 2 ways:
1) if (UCA0RXBUF == 66)
2) if (UCA0RXBUF & 0x42)
#include <msp430.h> int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT volatile unsigned int i; /* Use Calibration values for 8MHz Clock DCO*/ DCOCTL = 0; BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; /* Configure Pin Muxing P1.1 RXD and P1.2 TXD */ P1SEL = BIT1 | BIT2 ; P1SEL2 = BIT1 | BIT2; P1DIR |= 0x01; /* Place UCA0 in Reset to be configured */ UCA0CTL1 = UCSWRST; /* Configure */ UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 = 69; // 8MHz 115200 UCA0BR1 = 0; // 8MHz 115200 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 /* Take UCA0 out of reset */ UCA0CTL1 &= ~UCSWRST; /* Enable USCI_A0 RX interrupt */ IE2 |= UCA0RXIE; if (UCA0RXBUF & 0x42) { P1OUT |= BIT0; // Set P1.0 High i = 30000; // SW Delay do i--; while(i != 0); P1OUT &= ~BIT0; // Set P1.0 Low } else { P1OUT &= ~BIT0; } __bis_SR_register(GIE); // Enter LPM0, interrupts enabled } /* 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 }