Jump to content

Uart configurator

Recommended Posts

I was playing last days with MSP5xx UART, and every time after changing baud rate, need to calculate configuration again, and again, and again...


I write small program for making configuration depending on clock and baud rate. After generation, just press mouse button on first/second listing (nothing will happen) and use [CTRL]+[C] for copy listing to clipboard.




Link to post
Share on other sites

In MSP430F5xx USB Developers Package, example C7 (CDC) is USB/Uart bridge project. Don't understand why they (TI) made support for few baud rates (9600, 19200, 38400, 57600, 115200) and not for any possible baud rate (function USBCDC_handleSetLineCoding in usbEventHandling.c). 10 minutes job, 10 minutes. :roll:

Link to post
Share on other sites
  • 2 weeks later...

In MSP430F5xx USB Developers Package, example C7 (CDC), USB/Uart bridge will work only if uC is running by 20MHz. If any other frequency is defined (USB_MCLK_FREQ in descriptors.h file) it will not work, because uart in USBCDC_handleSetLineCoding function (usbEventHandling.c file) is configured only for 20 MHz.


/* This event indicates that new line coding params have been received from the host */

BYTE USBCDC_handleSetLineCoding (BYTE intfNum, ULONG lBaudrate)
   UCA0CTL1 = UCSSEL_2;                     // SMCLK

   //TO DO: You can place your code here
   switch (lBaudrate) {
       case 9600:
           UCA0BR0 = 0x23;                   // 20MHz 9600 (see User's Guide)
           UCA0BR1 = 0x8;                    // 20MHz 9600
       case 19200:
           UCA0BR0 = 0x11;                   // 20MHz 9600 (see User's Guide)
           UCA0BR1 = 0x4;                    // 20MHz 9600            
       case 38400:
           UCA0BR0 = 0x08;                   // 20MHz 9600 (see User's Guide)
           UCA0BR1 = 0x2;                    // 20MHz 9600            
       case 57600:
           UCA0BR0 = 0x5B;                   // 20MHz 9600 (see User's Guide)
           UCA0BR1 = 0x1;                    // 20MHz 9600            
       case 115200:
           UCA0BR0 = 0xAD;                   // 20MHz 9600 (see User's Guide)
           UCA0BR1 = 0x0;                    // 20MHz 9600            
   UCA0MCTL = UCBRS_3+UCBRF_0;              // Modulation UCBRSx = 3

   return (FALSE);                          // return FALSE to go asleep after interrupt
                                            // (in the case the CPU slept before interrupt)

I will re-write this function (soon, don't have IAR/CCS downloaded/installed on PC now) to support any baud rate (for example 123456 bps, 345678 bps...) on uC running by any clock frequency.

Link to post
Share on other sites

As long as we're pointing out alternatives, the BSP430 peripheral modules have code to configure support for arbitrary baud rates on the USCI(2xx/4xx), USCI5(5xx/6xx), and eUSCI(FR5xx) boards. ACLK or SMCLK are selected based on the requested baud rate and the current speed of those clocks.


The implementation might also be of value as a reference. Also note that though USCI and USCI5 are pretty close in interface, eUSCI is a new beast when it comes to configuring baud rates.

Link to post
Share on other sites
  • 1 month later...
  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...