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.

Transmitting Bytes via UART (USCI_AO) with MSP430G2553 in CCS (C code)

Other Parts Discussed in Thread: MSP430G2553

So I am trying to get the UART working on my MSP430G2553 and am having some difficulty.

I am assuming that once the UCA0TXBUF is loaded with a value it is then transmitted.  However the control and modulation registers must be set accordingly (which I have attempted - see that attached C file).  I am trying to do 9600bps, asynchronous, no parity, 1 stop bit with a 1MHz clock (from the DCO).

All I am interested is getting the USCI_AO to spit a byte (or bytes) out right now so after initalization I intentionlly get stuck in the following while loop where I try to send the byte 0x01 out.

    while(1)
    {
        UCA0TXBUF = 0x01;   //Sending a byte to the UCAOTXBUF
    }

I am not seeing anything coming out of pin 4 (USCI_A0) on my oscilloscope could somebody maybe help me get on the right track?

Thanks,

Corin

//*****************************************************************************
//  Blink LED Example
//
//  Description: Toggles P1.0 by xor'ing P1.0 inside of a software loop.
//               This example demonstrates the ease of starting a MSP430
//               project that interacts with the outside via GPIO pins.
//
//                   MSP430
//             -----------------
//         /|\|              XIN|-
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//            |             P1.0|-->LED
//
//  Texas Instruments Inc.
//*****************************************************************************

/*
 * ======== Standard MSP430 includes ========
 */
#include <msp430.h>

/*
 * ======== Grace related includes ========
 */
//#include <ti/mcu/msp430/Grace.h>

/*
 *  ======== main ========
 */
void CLK_INIT(void)
{
    /* USER CODE START (section: BCSplus_graceInit_prologue) */
    /* User initialization code */
    /* USER CODE END (section: BCSplus_graceInit_prologue) */

    /*
     * Basic Clock System Control 2
     *
     * SELM_0 -- DCOCLK
     * DIVM_0 -- Divide by 1
     * ~SELS -- DCOCLK
     * DIVS_0 -- Divide by 1
     * ~DCOR -- DCO uses internal resistor
     *
     * Note: ~<BIT> indicates that <BIT> has value zero
     */
    BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0;

    if (CALBC1_1MHZ != 0xFF) {
        /* Follow recommended flow. First, clear all DCOx and MODx bits. Then
         * apply new RSELx values. Finally, apply new DCOx and MODx bit values.
         */
        DCOCTL = 0x00;
        BCSCTL1 = CALBC1_1MHZ;      /* Set DCO to 1MHz */
        //DCOCTL = CALDCO_1MHZ;
        DCOCTL = 0x60;				//effectively the same as line above?
    }

    /*
     * Basic Clock System Control 1
     *
     * XT2OFF -- Disable XT2CLK
     * ~XTS -- Low Frequency
     * DIVA_0 -- Divide by 1
     *
     * Note: ~XTS indicates that XTS has value zero
     */
    BCSCTL1 |= XT2OFF + DIVA_0 + RSEL0+ RSEL2 + RSEL3;  //

    /*
     * Basic Clock System Control 3
     *
     * XT2S_0 -- 0.4 - 1 MHz
     * LFXT1S_2 -- If XTS = 0, XT1 = VLOCLK ; If XTS = 1, XT1 = 3 - 16-MHz crystal or resonator
     * XCAP_1 -- ~6 pF
     */
    BCSCTL3 = XT2S_0 + LFXT1S_2 + XCAP_1;

    /* USER CODE START (section: BCSplus_graceInit_epilogue) */
    /* User code */
    /* USER CODE END (section: BCSplus_graceInit_epilogue) */
}

void Port_INIT(void)
{
	P1DIR = BIT0+BIT2;

	P1SEL = BIT2; // Primary peripheral module function is selected.
				  // With the following line commented out (//P1SEL2 = BIT2;)

	//P1SEL2 = BIT2; // Secondary peripheral module function is selected.
					 // (if P1SEL and P1SEL2 are set high)
}

void UART_init(void){

	//int i = 0;
	//UCSWRST = 0x00;
	UCA0BR0 = 0x6D;		//Baud rate settings for 1MHz (9600bps)
	UCA0MCTL = 0x04;	//Baud rate settings for 1MHz (9600bps)

	//UCBRS = 0x02;
	//UCA0BRS0
	//UCA0CTL0 = 0x00;
	//UCA0MCTL = 0x00;
	//UCA0TXIE = i;
	//UTXEx = 1;
	while(1)
	{
		UCA0TXBUF = 0x01;   //Sending a byte to the UCAOTXBUF
	}
}

void initialize1(void)
{
    /* Stop watchdog timer from timing out during initial start-up. */
    WDTCTL = WDTPW | WDTHOLD;

	CLK_INIT();
	Port_INIT();
	UART_init();
}


void main(void)
{
    //Grace_init();                   /* Run Grace-generated initialization */


	initialize1();

    while (1) {
        P1OUT ^= BIT0;              /* Toggle LED on P1.0 */
        __delay_cycles(100000);     /* Wait ~100ms at DCO clock of ~1MHz */
    }
}

  • Corin,

    Looking at the User's Guide (http://www.ti.com/lit/ug/slau144i/slau144i.pdf) on page 441, it would appear that you need to take the UART out of reset (clear bit 0 in UCA0CTL1).

    UCA0BR0 should be 0x68 for 9600.

    Also, I think you need to select the clock source in UCA0CTL1 (bits 7&6).

  • Thanks Brian, there was a little more to it than that but you definitely got me on the right track.  I will update when I get the chance with the pertinent information.  May be a while because I am pretty swamped right now.

    Thanks again,

    Corin

  • It's a good idea to create a UART_init routine to setup the UART

    One of the first things one must do in setting up the UART is taking the UART out of Software Reset by setting the UCSWRST bit (bit 0 on the UCAO Control register 1) high:

    UCA0CTL1 = UCSWRST;

    Next we need to configure the UCA0 control register 0:

    UCA0CTL0 = 0x0;

    This is to set the baud rate, parity, stop bit etc. setting all bits to zero will default in a 9600 baud, 8 data bits, 1 stop bit UART configuration.

    The next step is to select the clock source for the UART, setting the 6th and 7th bits high on the USCI_AO Control Register 1 will select the MCLCK (DCO):

    UCA0CTL1 |= BIT6+BIT7;

    Next we need to set up the baud rate control registers from the table on page 435 for 8MHz clck and 9600 baud rate:

    UCA0BR1 = 0x03;

    UCA0BR0 = 0x41;

    UCA0MCTL = 0x04;

    Next I set the direction of the Tx port (P1.2) to an output:

    P1DIR |= BIT2;

    And finally I set the both the Peripheral Select bits to high to indicate we will use the secondary peripheral function of the port (UART functionality).

    P1SEL |= BIT2;

    P1SEL2 |= BIT2;

    Lastly at the end of my routine I clear the reset bit:

    UCA0CTL1 &= (0xFF - UCSWRST);

    Once this initialization routine has been called one can simply set the UCAO Transmit Buffer (UCA0TXBUF) equal to the byte you desire to send:

    UCA0TXBUF = 0x10

**Attention** This is a public forum