# MSP430 Choppy UART

I am having issues with the UART on the MSP430FR5969 microcontroller. I am sending about 85 characters 100 times per second for a data acquisition system. I am using 115200 baud rate which should be sufficient. When I view the serial output in a terminal program, I get chunks of ~4000 characters every few hundred milliseconds. Since the data is time sensitive, I would like it to come in steadily.

Here is the guts of the code with the data acquisition specifics removed.

#include <msp430.h>

unsigned char counter = 0;

int main(void) {
init();             // Initialize MSP430

while(1) {
write_data_to_uart();
}
}

void init() {
WDTCTL = WDTPW | WDTHOLD;    // Stop watchdog timer

P2SEL0 &= ~(BIT5);           // USCI_A1 UART TX line
P2SEL1 |=  (BIT5);

// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;

// Clock System Setup
// ---------------------------------------------------------------------
CSCTL0_H = CSKEY >> 8;                    // Unlock CS registers
CSCTL1 = DCOFSEL_4 | DCORSEL;             // Set DCO to 16MHz
CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;  // Set SMCLK = MCLK = DCO
// ACLK = VLOCLK
CSCTL3 = DIVA__2 | DIVS__1 | DIVM__2;     // Set all dividers to 1
CSCTL0_H = 0;                             // Lock CS registers
// ---------------------------------------------------------------------

// Configure USCI_A1 for UART mode
// ---------------------------------------------------------------------
UCA1CTLW0 = UCSWRST;                       // Put eUSCI in reset
UCA1CTLW0 |= UCSSEL__SMCLK;                // CLK = SMCLK
UCA1BR0 = 8;                               // 115200 baud rate
UCA1BR1 = 0x00;
UCA1MCTLW |= UCOS16 | UCBRF_10 | 0xF700;
UCA1CTLW0 &= ~UCSWRST;                     // Initialize eUSCI
}

void write_data_to_uart() {
char i;
uart_write_byte(counter);
counter++;
for(i = 0; i < 85; i++) {
uart_write_byte(0x30);
}
uart_write_byte(0x0D);                  // Carriage return
uart_write_byte(0x0A);                  // Line feed
}

void uart_write_byte(char x) {
while(!(UCA1IFG & UCTXIFG));
UCA1TXBUF = x;
}


I feel like the issue has to do with a misconception on my part about UART. Is there some sort of timer setup I should be using to steadily feed the data into the TX buffer?

• Are you using a USB to serial converter? It's probably some sort of buffering going on with that, maybe try a different one if you can get one. Could be the terminal program too I guess, might be worth trying a different one. – PeterJ Jan 6 '15 at 3:29
• Came here to say buffering on host side but @PeterJ already did :) Can you look at the uart lines with a scope or logic analyzer? You could prove it to yourself that way. – Some Hardware Guy Jan 6 '15 at 3:32
• I don't know why I didn't think to try that... been a long day! But it appears that there is steady data coming from the microcontroller - I don't see any long pauses. Thank you! – dgreenheck Jan 6 '15 at 3:44
• You might need to consider flow control. – downbeat Jan 6 '15 at 4:27