Part Number: MSP430FR2512
Tool/software: Code Composer Studio
Hi I'm not sure which part of my code is wrong as I cannot get the Uart to communicate through USB serial connection into the tera term software for it to display the hello world. is it I set the wrong baud rate. or the wrong pin and register? im new to this firmware coding thing...
#include <stdio.h>
#include <msp430fr2512.h>
#define TXLED BIT0
#define RXLED BIT6
#define TXD BIT0
#define RXD BIT1
const char string[] = { "Hello World\r\n" };
unsigned int i; //Counter
/**
* hello.c
*/
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
// DCOCT_L = 0; // Select lowest DCOx and MODx settings<
// BCSCTL1 = CALBC1_1MHZ; // Set DCO //******************************not sure about this
// DCORSEL = CALDCO_1MHZ;
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
P2DIR |= TXD; // All P2.x outputs<
P2DIR &= RXD;
P2OUT &= 0x00; // All P2.x reset
P2SEL0 |= RXD + TXD ; // P2.1 = RXD, P2.0=TXD
P2SEL1 &= ~RXD ; // P2.1 = RXD, P2.0=TXD
P2SEL1 &= ~TXD ;
P1DIR |= RXLED + TXLED;
P1OUT &= 0x00;
UCA0CTLW0_L |= UCSSEL_2; // SMCLK //edited this to add the _L cuz 8 bit previously 16BIT
UCA0BR0 = 0xF7; // 1MHz 115200
UCA0BR1 = 0x00; //
UCA0MCTLW = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt
UCA0IE |= UCTXIE;
// __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until Byte RXed
while (1)
{
UCA0TXBUF = string[i++]; // TX next character
if (i == sizeof string - 1) // TX over?
i=0;
//UCA0IE &= ~UCTXIE; // Disable USCI_A0 TX interrupt
return 0;
}
}
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
P1OUT |= RXLED;
if(UCA0IFG&UCRXIFG)
{
if (UCA0RXBUF == 'a') // 'u' received?
{
i = 0;
UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt
UCA0TXBUF = string[i++];
}
}
else if(UCA0IFG&UCTXIFG)
{
UCA0TXBUF = string[i++]; // TX next character
if (i == sizeof string - 1) // TX over?
UCA0IE &= ~UCTXIE; // Disable USCI_A0 TX interrupt
}
P1OUT &= ~RXLED;
}
//#pragma vector=USCI_A0TX_VECTOR
//__interrupt void USCI_A0TX_ISR(void)
//{
// P1OUT |= TXLED;
// UCA0TXBUF = string[i++]; // TX next character
// if (i == sizeof string - 1) // TX over?
// UCA0IE &= ~UCTXIE; // Disable USCI_A0 TX interrupt
// P1OUT &= ~TXLED;
//}