I am new to serial communication and have been running into some issues. I have been trying to interface my msp430g2553 chip with my XBee modules and have not had much success. Using RealTerm, I would like to be able to press a button on my protoboard and have the chip send a message to the terminal via XBee wireless communication. Also, I would like to send a value from the terminal to the chip and light up an LED on the board. I found this code online and attempted to modify it to do what I had in mind.
#include "msp430g2553.h"
#define BOUNCINGDELAY 250000
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
if(CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF)
while(1);
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
P1REN = BIT5;
P1OUT |= BIT5;
P2SEL = 0;
P2SEL2 = 0;
P2DIR |= (BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5 | BIT6 | BIT7);
P2OUT &= ~(BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5 | BIT6 | BIT7);
P1IE |= BIT5;
P1IES &= ~BIT5;
P1IFG &= ~BIT5;
P1SEL = BIT1 | BIT2; // P1.1 = RXD, P1.2 = TXD
P1SEL2 = BIT1 | BIT2; // P1.1 = RXD, P1.2 = TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 138; // 16MHz 9600
UCA0BR1 = 0; // 16MHz 9600
UCA0MCTL = UCBRS_7; // Modulation UCBRSx = 6
UCA0CTL1 &= ~ UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
_BIS_SR(GIE);
while(1);
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
switch(UCA0RXBUF)
{
case 1:
P2OUT |= BIT0;
P2OUT &= ~BIT7;
break;
case 2:
P2OUT &= ~BIT0;
P2OUT |= BIT7;
break;
default:
P2OUT &= ~(BIT0 | BIT7);
}
}
#pragma vector = PORT1_VECTOR
__interrupt void Port_1(void)
{
if(P1IFG & BIT5)
{
int i = 0;
char string[] = "Hello guys!";
while(string[i] != '\0')
{
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = string[i];
i++;
}
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = '\r';
_delay_cycles(BOUNCINGDELAY);
P1IFG &= ~BIT5;
}
P1IFG = 0;
}
Not only did this code not work for me, I ran into some peculiarities while experimenting with the board. I am using an XBee Explorer Regulated to attached one of the XBees to the protoboard. I removed the connection from my 9-Volt to the 5V pin on the Explorer and noticed that power was getting into the Explorer via the DOUT pin which is connected to the TXD pin of my chip? Maybe some information on how these pins are configured would be helpful? Furthermore, I have used X-CTU to configure both modules with the same baud rate. I have also been able to get the RSSI LED to light up on my boards XBee by sending a command through the terminal. Other than that, no message is sent to the terminal when I press the button and no LED lights up when the terminal sends to the board. Any information would be appreciated. Thanks!