I'm trying to learn how to use UART on a MSP430G2553 and I wrote this simple program. The program should set up a timer interrupt to happen once a second. The interrupt service routine should toggle a LED, send a count value to my laptop using UART, and increment the counter. My SMCLK is set to 125 kHz, so I set UCOS16 to 1 to use oversampling, UCBR1 to a prescalar of 1, and UCBRF1 to a modulation value of 10 for a baud rate of 4800. Below is my code:
#include <msp430.h>
volatile unsigned int count = 0; //global variable to increment every timer interrupt and send through UART - must be volatile because ISR can change it at any time
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
//set clock to 1 MHz and to use DCO
DCOCTL = DCO1 + DCO0;
BCSCTL1 = RSEL0 + RSEL1 + RSEL2;//7;
BCSCTL2 = DIVS0 + DIVS1; //SMCLK = MCLK / 8, everything else 0 so it uses DCO as source
//UART settings
UCA0CTL1 = UCSSEL1 + UCSWRST; //set SMCLK as source and put UCA0 in reset state
UCA0CTL0 = 0; //parity disabled, LSB first, 8 bit data, UART mode
UCA0BR0 = 1; //want prescalar of 1 - prescalar of 1, modulation of 10 and SMCLK of 125 kHz should result in baud rate of 4800
UCA0BR1 = 0; //want prescalar of 1
UCA0MCTL = UCBRF_10 + UCOS16; //modulation of 10 and oversampling enabled
UCA0CTL1 &= ~UCSWRST; //take UCA0 out of reset state
//timer settings
TA0CTL = TASSEL1 + ID1 + ID0 + MC1 + TACLR; //set SMCLK as source, divide source by 8, set to continuous mode, enable interrupts
TA0CCTL1 &= ~CAP; //set CAP to 0 for compare mode
TA0CCTL1 |= CCIE; //enable interrupts
TA0CCR1 = 15625; //1usec * 8 * 8 * 15625 should give an interrupt once a second
//set pin 1 for output
P1DIR = BIT0;
//enable interrupts globally
_EINT();
LPM0;
}
#pragma vector = TIMER0_A1_VECTOR
__interrupt void Timer_A (void) {
TA0CCR1 += 15625; //reset counter
TA0CCTL1 &= ~CCIFG; //clear flag
P1OUT ^= BIT0; //toggle LED
//wait for USCI to be inactive
while((UCA0STAT & UCBUSY) == 1) {
};
UCA0TXBUF = count; //send current count value via UART
count++; //increment count
}
I can tell the timer interrupt is working because the LED is blinking once a second. However, when I set up PUTTY to try to watch the count value increase every second, no characters or values ever show up. I've tried sending chars and ints that don't change instead of the count value, but that doesn't seem to help. I've also set a breakpoint in the timer interrupt service routine and I'm able to step through it, but nothing shows up on PUTTY. Does anyone know what might be going on?