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.

Serial communication using MSP 430.

Other Parts Discussed in Thread: MAX3232, MSP430FG4618

       Hello everyone. I am new to msp430. I tried led blinking and also I displayed some characters in the LCD display. Now I want to perform serial communication. Could you please tell me how to do it?  I have done serial communications in other microcontrollers but I don't know how to do that using MSP430. I would be really happy if you could help me by giving me the code or some other link for serial communication using msp430.

Thanks in advance.

  • The answer to your question depends on the MSP you use.

    Typically, teh MSPs have one fo three kinds of communicationsmodules.

    First, the USI. It doe snonly support synchronous transfers (it is a better hardware shift register). If you want to do UART transfers on such an MSP, you'll have ot do it in software, using the timer and CCR units to send the data bit by bit.
    The demo software for the LaunchPad contains code for a 2400Bd software UART (with a calibrated clock, more than 2400Bd are possible).

    Next is the USART module. It supports asynchronous UART transfers. It is found mostly on the 1x family.
    Finally, there is the USCI module, or the improved eUSCI. It supports asnychronous UART transfers too.

    For the USCI, there is sample code for a simple echo (PC->MSP->PC) loop available. Look on the MSPs product page for a link to demo software and applicaiton notes.
    Also, there are several threads in this forum talking about this, and how to turn the demo code into a real bi-directional transceiver.

    keep in mind, that for communicationw ith PC, you'll need a level shifter, since PC COM ports emit -+3V--+12V symmetrical and inverted signals while the MSP requires a TTL-level signal (GND/VCC). The MAX3232 does this job.
    Or you have an USB/serial adapter that provides a TTL-compatible output (usually GND/5V). in this case a simple series resistor of 1k on the RX and TX lines is sufficient, to limit the input current caused by the higher signal voltage to below the allowed 2mA. (not energetically the best solution, but for experiments...)

  •  Can you provide me the code or atleast give me the link for serial communication using UART mode.

    Thanks in advance

  • I still do not know which MSP you're using. There are ~400 different.

  •  Do you mean each msp430 has an entirely different code. I thought they would be somewhat similar atleast. Anyway the msp that I am having is msp430fg4618

  • Not each MSP430 has an entirely different code - but each module has, and without knowledge of the MSP, we don't know which modules it will have. And posting example code for every module is not quite the best thing to do.

    But now, as you can see on the product page of the MSP430FG4618 there is example code from TI available. In there you can find examples for the USART module and the USCI module in UART configuration.

    msp430xG46x_usart1_uart_9600.c

    msp430xG46x_uscia0_uart_9600.c

    These might serve as a starting point, to get to know the defines and a rough feeling on what's going on. I don't recommend on copying these examples - it's not that much to write anyway and creating the software by hand is a good exercise for future work with the msp. 

  • I saw the code for UART. It's saying that it's would echo the received byte but I don't find any interrupt function for the transmission part.

    #include  <msp430xG46x.h>

    void main(void)
    {
    volatile unsigned int i;

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    FLL_CTL0 |= XCAP14PF; // Configure load caps

    do
    {
    IFG1 &= ~OFIFG; // Clear OSCFault flag
    for (i = 0x47FF; i > 0; i--); // Time for flag to set
    }
    while ((IFG1 & OFIFG)); // OSCFault flag still set?

    P4SEL |= 0x03; // P4.1,0 = USART1 TXD/RXD
    ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
    U1CTL |= CHAR; // 8-bit character
    U1TCTL |= SSEL0; // UCLK = ACLK
    U1BR0 = 0x03; // 32k/9600 - 3.41
    U1BR1 = 0x00; //
    U1MCTL = 0x4A; // Modulation
    U1CTL &= ~SWRST; // Initialize USART state machine
    IE2 |= URXIE1; // Enable USART1 RX interrupt

    _BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
    }

    #pragma vector=USART1RX_VECTOR
    __interrupt void USART1_rx (void)
    {
    while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
    TXBUF1 = RXBUF1; // RXBUF1 to TXBUF1
    }
    
    
    Could you please clear my doubt? 
  • This example will only do something if there was a byte received over the UART. So the receive triggers the RX ISR - it will check if the USART is ready to transmit another byte, if it's ready it will send the just received byte back again (filling TXBUF1 - the actual transmit will happen without any software interference)

    This does not require a TX ISR. Typically a TX ISR is used to fill the buffer with the next byte for transmission to get the fastest possible transmit while still being able to do calculations or other stuff.

**Attention** This is a public forum