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.

MSP430F5310 UART Communication and example

Other Parts Discussed in Thread: MSP430F5310

Hey, 

I am developing a device that goes on a mini-computer embedded system. The communication between device and mini-computer happens by UART.

My device uses MSP430F5310 as it's microcontroller. I went through the FOUR example codes (in slac469e) of UART. They do not provide variety. 

I would like to transmit a locally generated character array (64 characters) by UART. What all examples teach me is to echo the received character, I could not find any that explains the way to explicitly transmit a string by UART. 

So I used those examples to derive a way. I wait for TX buffer to be ready and then transmit one character, and then wait for it to be ready again and then transmit next character, and so on, till all 64 are transmitted.

while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = rx_message[1]; while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = rx_message[2]; while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = rx_message[3]; while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF = rx_message[4]; while (!(UCA1IFG&UCTXIFG));

....

Now this doesn't work efficiently. If I do this 10 times, only one time the message is flawlessly sent to the other end. 

So I do this thing 20 times repeatedly in for loop to ensure that my message reaches there at least once.

What is the ideal way to do this? To transmit a string (char array) by UART?

My settings are: 

P4SEL |= BIT4 | BIT5; // P4.4, 4.5 = USCI_A1 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_2; // SMCLK
UCA1BR0 = 9; // 1MHz 115200 (see User's Guide)
UCA1BR1 = 0; // 1MHz 115200
UCA1MCTL |= UCBRS_1 | UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt
__bis_SR_register(GIE); // Enter LPM0, interrupts enabled

  • You can also dig into more examples, the SPI examples describes a way to send more than one byte.

    Then tries to learn about the use of Array’s and Pointers, you can use this source but there are many others available: http://publications.gbdirect.co.uk/c_book/

  • Use TX_IRQ

    At boot up TX_IE: off, TX_IFG=set

    main
    {
    J=0
    TX_IE= enable
    bis_lmp0bits /* sleep */
    }

    IRQ:
    TXBUF=buffer[J++]
    if J=64
    {
     TX_IE=off
     bic_lpm0bits_on_exit
    }
    reti

  • The echo examples aren’t the best to learn how to work with the USCI. They show how to use the USCI, but in a very specific way for a very specific purpose. And by doing a lot of implicit assumptions which are true only for the sole case of echoing a character.
    Sending more than one character at once in an ISR is a death sin. Waiting for a condition in an ISR is another one. (but since send and receive speed are identical in this demo – which is not necessarily true if you want do a baudrate converter -  you can’t receive faster than you send and the waiting loop never has to wait).

    To send your text, do it in your main code and without using ISRs (and don’t activate the interrupt then in the USCI init).

    For the effectiveness of the code, well, the number in the brackets does not need to be a constant. Replace it by a variable and put just one instance of your write command inside a loop. Well, this is not microcontroller specific but rather basic C coding.

**Attention** This is a public forum