This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR59941: UART Communication Issue dropping characters

Part Number: MSP430FR59941

Tool/software:

I am trying to program a MSP430FR59941 to send and receive messages over UART0 using a ISR. I am dropping equivalent to every other character and only receiving back half the message. 

I have the Baud set to 9600. I have looked at the comms on a scope and there is only a little bit of noise. I'm not sure how else to debug this.

  • Can you show us your ISR? Sometimes all it takes is a typo.

  • // UART RX ISR
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=EUSCI_A0_VECTOR
    __interrupt void EUSCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR(void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG)){
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
    if(!message_ready){
    receivedChar = UCA0RXBUF;

    if(receivedChar == '\n' || buffer_index >= MAX_BUFFER_SIZE -1){
    message_ready =1;
    UART_send_string(rx_buffer);
    buffer_index = 0;

    }else{
    rx_buffer[buffer_index++] = receivedChar;
    //UART_send_string(rx_buffer);
    }
    }
    break;
    default: break;
    }
    }

  • 1) > UART_send_string(rx_buffer);

    Sight unseen I suspect this takes a long time (multiple milliseconds), during which any Rx bytes are lost (overrun). I suggest you move this to main().

    2) More generally, Rx bytes will be dropped (ignored) as long as message_ready == 1. I suggest that main() strive to retrieve the contents of rx_buffer[] and set message_ready=0 fairly quickly. It has 1ms (at 9600bps) to do this, which is actually a not-unreasonable amount of time.

  • I can take out the write that is in the ISR. I am only sending one message at a time. By the time the first message ready = 1 there should not be any messages after for a couple seconds. 

  • I supposed (from the code) that the response was missing data in blocks (first half, e.g.) but I should have asked: Is there a pattern to the missing bytes? E.g. every other byte vs long gaps.

  • It seemed to be every other byte. Once I started tripping all of the logic out of the ISR it seemed to be less frequent. 

    This is all that is in the ISR routine now and it seems to work on the launchpad fairly well.  Every once in a while I will miss a character but it seems more consistent now. 

    I will program on the micro in my application to verify that it is working correctly now.

    // UART RX ISR
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=EUSCI_A0_VECTOR
    __interrupt void EUSCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR(void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG)){
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
    receivedChar = UCA0RXBUF;

    rx_buffer[buffer_index++] = receivedChar;
    break;
    default: break;
    }
    }

  • It seemed to be every other byte.

    I am wondering about the relationship between MCLK and the bit clock. If you have left the clock system at its power up defaults,  MCLK will be 1MHz. Which seems plenty fast but sometimes it isn't. Changing to 8MHz is as simple as setting DIVM=0.

    Unless you protect the code in the main routine that changes buffer_index by disabling interrupts, your buffering code is problematic.

  • I was using 1MHz. what is the syntax for changing the clock to 8MHz? I also cleaned up my ISR which seemed to help a lot. It works pretty consistently on the launchpad but when I burn it to my on board application it seems to miss 2 out of 15 characters I am trying to send. The incoming uart does have a little bit of noise looking on the oscilloscope. but I'm not sure that's what is causing the loss.  

    Here is my ISR

    // UART RX ISR
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=EUSCI_A0_VECTOR
    __interrupt void EUSCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR(void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG)){
    case USCI_NONE: break;
    case USCI_UART_UCRXIFG:
    receivedChar = UCA0RXBUF;

    rx_buffer[buffer_index++] = receivedChar;
    break;
    default: break;
    }
    }

  • Example msp430fr599x_cs_01.c demonstrates setting S/MCLK to 8MHz. You can probably just copy/paste the code directly.

    https://dev.ti.com/tirex/explore/node?node=A__ADtHzr9Ec707pVOoi2fkQw__msp430ware__IOGqZri__LATEST

  • Thank you! I am also using the FT234XD-x to convert uart to usb to communicate with my PC. Would you know if I need some kind of line termination between the converter and the micro?

  • I'm not familiar with the FT234 specifically, but I haven't had trouble with FT23x devices; I expect you can connect it directly. (Make sure it's a 3.3V version.)

**Attention** This is a public forum