Open Source UART Driver now on github

To  make it easier to access the code, I’ve added and improved it on github. It lets me fix and add features quickly.

https://github.com/glitovsky38412/msp430uartdriver

I’ve restructured the code so the actual UART driver is separate from the example code. Adds a bit more complexity to the project, but makes it easier to reuse code.
It’s a nice example of creating portability in CCS projects.
The EZ430-RF2500 project also compiles but I haven’t tested it on real hardware yet.

 

Enjoy.
Gustavo

5 thoughts on “Open Source UART Driver now on github

  1. Hi Gustavo!
    Great work out there. Your library looks awesome. Nice that it could be easily converted for other MSP430 platforms.

    Although I tried to use it with MSP430F247. It has UCA0 module like F2274.
    Whole project is building without any error or warning. Clock is set for 8MHz, baudrate is 9600. I use FTDI232RL breakout board from adafruit as bridge between PC and MSP430.
    When “Hello” is pushed threw UART to RealTerm i see only NUL chars. Nothing else.
    Maybe You know what is causing that problem. I’m trying to resolve this puzzle for 2 days with no further succes, I’m out of any ideas why it’s happening.

    Please help!
    Greetings, Tomek.

  2. Hi Tomek,
    Sounds like a baudrate error. How are you calling the driver? Can you show the code?

    Regards,
    Gustavo

  3. Thanks for fast reply Gustavo!

    Here is whole code from main.c:

    #include
    #include
    #include “uart.h”

    void setSMCLK8MHz();

    // UART Port Configuration parameters and registers
    UARTConfig cnf;
    USCIUARTRegs uartUsciRegs;
    USARTUARTRegs uartUsartRegs;

    // Buffers to be used by UART Driver
    unsigned char uartTxBuf[200];
    unsigned char uartRxBuf[200];

    void main(void)
    {
    // Disable MSP430 Watchdog Timer
    WDTCTL = WDTPW | WDTHOLD;

    // Configure Experimenter Board LED on P2.0 – Active High
    P2SEL &= ~BIT0;
    P2DIR |= BIT0;
    P2OUT |= BIT0;

    // Configure SMCLK to 8MHz
    setSMCLK8MHz();

    /********************************
    *
    * UART Specific Configuration
    *
    ********************************/
    initUartDriver();

    // Configure UART Module on UCA0
    cnf.moduleName = UCA0;

    // Use UART Pins P5.7 and P5.6
    cnf.portNum = PORT_3;
    cnf.RxPinNum = PIN5;
    cnf.TxPinNum = PIN4;

    // 115200 Baud from 8MHz SMCLK
    cnf.clkRate = 8000000L;
    cnf.baudRate = 9600L; // EZ430 allows only up to 9600 baud
    cnf.clkSrc = UART_CLK_SRC_SMCLK;

    // 8N1
    cnf.databits = 8;
    cnf.parity = UART_PARITY_NONE;
    cnf.stopbits = 1;

    int res = configUSCIUart(&cnf,&uartUsciRegs);
    if(res != UART_SUCCESS)
    {
    // Failed to initialize UART for some reason
    __no_operation();
    }

    setUartTxBuffer(&cnf, uartTxBuf, 200);
    setUartRxBuffer(&cnf, uartRxBuf, 200);

    enableUartRx(&cnf);

    /*********************************/

    __enable_interrupt(); // Enable Global Interrupts
    while(1)
    {
    // Send the string hello using interrupt driven
    uartSendDataInt(&cnf,(unsigned char *)”Hello\r\n”, strlen(“Hello\r\n”));
    _delay_cycles(100000);
    int bytesAvailable = numUartBytesReceived(&cnf);
    if(bytesAvailable > 0)
    {
    unsigned char tempBuf[100];
    memset(tempBuf,0,100);

    volatile int bytesRead = readRxBytes(&cnf, tempBuf, bytesAvailable, 0);
    if(bytesRead == bytesAvailable)
    {
    // All requested bytes read. Do something with it.

    // If we receive the letter a, we toggle the LED
    if(tempBuf[0] == ‘a’)
    {
    P2OUT ^= BIT0;
    }
    }
    else
    {
    // Couldn’t read all the bytes we requested
    __no_operation();
    }
    }
    }
    }

    void setSMCLK8MHz()
    {
    BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz
    DCOCTL = CALDCO_8MHZ;
    }

    Only change I made in You example code is LED port and pin. I created new project in CCS, choose MSP430F247 as my hardware, add “uart.h” to #include search path.
    I double checked all USCI registers which was implemented by You in “uart.c” file and all are correct regarding to users guide and F247 datasheet.
    I think it’s baudrate error too so I checked using JTAG all USCI register. For 8MHz clock and 9600 baudrate register settings are:
    UCA0BR0: 0x34
    UCA0BR1: 0x00
    UCBRF: 0001
    UCBRS: 000
    UCOS16: 1

    Do You have any idea what could be wrong? Maybe You can guide me to look in other places in code to search for errors?

    Thanks in advance, Tomek

    1. Ok, I’ve got something.

      I checked You library with Launchpad MSP430G2553 dev board (the same USCI – UCA0).
      When I use built in Lauchpad USB port and switch jumper settings to “HW UART” everything work excellent.
      But when I connect my FT232RL breakout board it’s behave in the same way as in MSP430F247 – NUL chars in terminal.
      FT232RL breakout board works ok in my other projects.
      Maybe my connections are wrong?

      Here is my configuration:
      FT232RL RX -> Launchpad TX
      FT232RL TX -> Launchpad RX
      FT232RL GND -> Launchpad GND
      FT232RL VCC -> Launchpad VCC (dev board powered from FT232RL)

      What do You think Gustavo?

      1. SUCCESS!!

        Solution for the problem was replacing FT232RL.
        It seems that it wasn’t working properly, resoldering the chip solve whole issue.

        I must admit again Your Library is AWESOME and I love it!

        I recommend everybody to use it, it’s very simple to adapt to Your project so don’t hesitate to try it.

        Gustavo, thank You very much for help.
        Regards, Tomek

Leave a Reply

Your email address will not be published. Required fields are marked *