2
\$\begingroup\$

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?

\$\endgroup\$
4
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – PeterJ Jan 6 '15 at 3:29
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Some Hardware Guy Jan 6 '15 at 3:32
  • \$\begingroup\$ 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! \$\endgroup\$ – dgreenheck Jan 6 '15 at 3:44
  • \$\begingroup\$ You might need to consider flow control. \$\endgroup\$ – downbeat Jan 6 '15 at 4:27
1
\$\begingroup\$

You may have removed it but I do not see any delay between your calls to write_data_to_uart(). Are you sleeping for sufficient time between your calls?

What is on the receiving side of the UART? An acutal serial port or a USB Serial converter?

The best way to pace the data going out of the uC is to write your data to a memory location, hook up to a timer interrupt and kick off a DMA transfer using the DMA from memory to UCA1TXBUF. This method has caused the least jitter in the past and I was able to put uC in a low-power state.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.