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?