Hey,
I am new to embedded programming and I want to set up UART communication on the MSP430FR2311 to send data to my serial port. I have attached code below and basically I am trying to using the TX buffer register: UCA0TXBUF to read a value of 2 I assigned to TX. However, when I open my COM port on my computer at a baud rate of 4800 I don't see a value of 2. What do I need to do in order to see that value?
#include <msp430.h>
#include <stdint.h>
unsigned char TX = 2;
void Init_GPIO();
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Configure GPIO
Init_GPIO();
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate 1previously configured port settings
// Configure UART pins
P1SEL0 |= BIT6 | BIT7; // set 2-UART pin as second function
// Configure UART
UCA0CTLW0 |= UCSWRST; //Sets softare reset enable
UCA0CTLW0 |= UCSSEL_1; // set SMCLK as BRCLK
// Changing baud rate to 115200
// Baud Rate calculation. Referred to UG 17.3.10
// (1) N=32768/4800=6.827
// (2) OS16=0, UCBRx=INT(N)=6
// (4) Fractional portion = 0.827. Refered to UG Table 17-4, UCBRSx=0xEE.
UCA0BR0 = 6; // INT(32768/4800)
UCA0BR1 = 0x00;
UCA0MCTLW = 0xEE00;
// UCA0BR0 = 8; // 1000000/115200 = 8.68
// UCA0MCTLW = 0xD600; // 1000000/115200 - INT(1000000/115200)=0.68
// UCA0BR1 = 0x00; // UCBRSx value = 0xD6 (See UG)
UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(LPM3_bits|GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_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,USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = TX;
__no_operation();
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}
void Init_GPIO()
{
P1DIR = 0xFF; P2DIR = 0xFF;
P1REN = 0xFF; P2REN = 0xFF;
P1OUT = 0x00; P2OUT = 0x00;
}