Jump to content
43oh

G2553 Hardware UART "Hello World" Example


Recommended Posts

  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

A simple well documented hardware uart "Hello World" example. Updated, thanks for member comments 3/13/13   Notes: This code is for launchpad rev 1.5 This is hardware UART, your launchpad jumpers

#include <msp430.h> #include <stdint.h> const unsigned RXD = BIT1; const unsigned TXD = BIT2; const unsigned SW2 = BIT3; const unsigned long smclk_freq = 16000000; // SMCLK frequenc

I had the same problem with the switched TX/RX pins on the launchpad. It took me a while to figure that one out...   I wrote my own library for the G2533, but should also work for the C2553. The ma

I think no matter what, that debounce in code is going to end up ugly. Personally, from all the debounce stuff I have read through in the past few months. That is probably the shortest, and most concise approach.

 

I was reading a post on HAD a couple weeks ago, and one of the guys in that article had well over 200 lines worth of debounce code . . . Somehow, he managed to win the mini "contest" they seemed to be doing. Personally, I thought his code was junk, but meh, whatever.

Link to post
Share on other sites

i m using code composer studio . is it possible to load program from there.

 

 

 

 

A simple well documented hardware uart "Hello World" example.
Updated, thanks for member comments 3/13/13

 

Notes:

This code is for launchpad rev 1.5

This is hardware UART, your launchpad jumpers must be set for hardware UART

The TI TUSB3410 is a TERRIBLE usb-> UART chip and is very buggy on WIN7 64bit. If your still having issues, it could be a driver issue. Try on XP or use a different USB -> serial device.

 

 

//Nate Zimmer UART example
// Press button to print hello to terminal

#include  <msp430g2553.h> // System define for the micro that I am using

#define RXD        BIT1 //Check your launchpad rev to make sure this is the case. Set jumpers to hardware uart.
#define TXD        BIT2 // TXD with respect to what your sending to the computer. Sent data will appear on this line
#define BUTTON    BIT3

void UART_TX(char * tx_data);            // Function Prototype for TX

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;         // Stop Watch dog timer

  BCSCTL1 = CALBC1_1MHZ;            // Set DCO to 1 MHz
  DCOCTL = CALDCO_1MHZ;

  P1DIR &=~BUTTON;                  // Ensure button is input (sets a 0 in P1DIR register at location BIT3)

  P1OUT |=  BUTTON;                 // Enables pullup resistor on button
  P1REN |=  BUTTON;

  P1SEL = RXD + TXD ;                // Select TX and RX functionality for P1.1 & P1.2
  P1SEL2 = RXD + TXD ;              //

  UCA0CTL1 |= UCSSEL_2;             // Have USCI use System Master Clock: AKA core clk 1MHz

  UCA0BR0 = 104;                    // 1MHz 9600, see user manual
  UCA0BR1 = 0;                      //

  UCA0MCTL = UCBRS0;                // Modulation UCBRSx = 1
  UCA0CTL1 &= ~UCSWRST;             // Start USCI state machine

  while(1)                          // While 1 is equal to 1 (forever)
  {
      if(!((P1IN & BUTTON)==BUTTON)) // Was button pressed?
      {
          UART_TX("Hello World! \r\n");  // If yes, Transmit message & drink beer
          __delay_cycles(100000); //Debounce button so signal is not sent multiple times
      }
  }

}

void UART_TX(char * tx_data) // Define a function which accepts a character pointer to an array
{
    unsigned int i=0;
    while(tx_data[i]) // Increment through array, look for null pointer (0) at end of string
    {
        while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data
        UCA0TXBUF = tx_data[i]; // Send out element i of tx_data array on UART bus
        i++; // Increment variable for array address
    }
}
Link to post
Share on other sites
  • 3 months later...

Thank you for the post, it worked really well on my g2553. But i really urgently need to solve my problem :), i'm new in coding.

i want to send ADC result on uart continuosly...

 

i need to accomplish sth like this function: 

 

unsigned int value;

----------

...

..

 

UART_TX(value);

--------------

 

it gives me random numbers, thats all :(

 

i could not achieve ofcourse, could you please help me, thank you in advanced..

 

........................

 

 

 #include  <msp430g2553.h> // System define for the micro that I am using

 
#define RXD        BIT1 //Check your launchpad rev to make sure this is the case. Set jumpers to hardware uart.
#define TXD        BIT2 // TXD with respect to what your sending to the computer. Sent data will appear on this line
#define BUTTON    BIT3
 
unsigned int value2;
 
//void UART_TX(char * tx_data);            // Function Prototype for TX
void UART_TX(unsigned int * value);            // Function Prototype for TX
 
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;         // Stop Watch dog timer
 
  BCSCTL1 = CALBC1_1MHZ;            // Set DCO to 1 MHz
  DCOCTL = CALDCO_1MHZ;
 
  P1DIR &=~BUTTON;                  // Ensure button is input (sets a 0 in P1DIR register at location BIT3)
 
  P1OUT |=  BUTTON;                 // Enables pullup resistor on button
  P1REN |=  BUTTON;
 
  P1SEL = RXD + TXD ;                // Select TX and RX functionality for P1.1 & P1.2
  P1SEL2 = RXD + TXD ;              //
 
  UCA0CTL1 |= UCSSEL_2;             // Have USCI use System Master Clock: AKA core clk 1MHz
 
  UCA0BR0 = 104;                    // 1MHz 9600, see user manual
  UCA0BR1 = 0;                      //
 
  UCA0MCTL = UCBRS0;                // Modulation UCBRSx = 1
  UCA0CTL1 &= ~UCSWRST;             // Start USCI state machine
  // set adc 
  ADC10CTL1 = INCH_5 + ADC10DIV_3 ;         // Channel 5, ADC10CLK/4
  ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
  ADC10AE0 |= BIT5;
  ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start, single measure!
 
while(1)                          // While 1 is equal to 1 (forever)
    
  {
      if(!((P1IN & BUTTON)==BUTTON)) // Was button pressed?
      {
        value2=ADC10MEM & 0x00FF;
        UART_TX(&value2);  // If yes, Transmit message & drink beer
        //UART_TX(value);  // send ADC value
          __delay_cycles(100000); //Debounce button so signal is not sent multiple times
      }
  }
 
}
 
void UART_TX(unsigned int * value) // Define a function which accepts a character pointer to an array
{
    unsigned int i=0;
    while(value) // Increment through array, look for null pointer (0) at end of string
    {
        while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data
        UCA0TXBUF = value; // Send out element i of tx_data array on UART bus
        i++; // Increment variable for array address
    }
}
 
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}
Link to post
Share on other sites

Join the conversation

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

Guest
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...