Tool/software: Code Composer Studio
Hi guys,
I'm having trouble with UART communication, I can't neither send or receive information. My baudrate is 9600 and i'm using Tera Term for the communication by the Usb cable. I have already change the tx and rx jacks of my launchpad.
My code is the following:
#include <msp430g2553.h>
#define BUTTON BIT3
void UART_TX(char * tx_data); // Function Prototype for TX
volatile char UARTRxData;
volatile int UARTRxFlag = 0;
volatile int UARTo= 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watch dog timer
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 104;
UCA0BR1 = 0;
UCA0MCTL = UCBRS0;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;// + UCA0TXIE;
__bis_SR_register(GIE);
while(1)
{
if(((P1IN & BUTTON)==BUTTON))
{
UART_TX("Hello World! \r\n");
}
}
void UART_TX(char * tx_data) // Define a function which accepts a character pointer to an array
{
unsigned int i=0;
while(tx_data[i]) // Increment through array, look for null pointer (0) at end of string
{
while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data
UCA0TXBUF = tx_data[i]; // Send out element i of tx_data array on UART bus
i++; // Increment variable for array address
}
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
UARTRxData = UCA0RXBUF;//Read USART data register
UARTRxFlag = 1;
}
Thank you