Hi all,
I am currently trying to use the MSP430G2553 (Launchpad) to send data to the PC using UART. Using the example code provided (below), I was able to do this with a clock of 1MHz. However, I am trying to use a clock of 16MHz and I am not sure what to do, I know how UCA0BR0 is calculated, but 16000000/9600 = 1667 which causes truncation in UCA0BR0.
Can someone explain to me how to get the 9600 Baud Rate with a 16MHz clock instead of a 1MHz clock? Is the UCA0BR1 value for when UCA0BR0 overflows? Also how does UCA0MCTL work, as I cannot find any useful help with setting that value in software from the user guides. Are there any other variables that I would need to set for using this 16MHz clock?
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(LPM0_bits + 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 = 'z';
}
Thanks,
Matt