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 IN LAUNCHPAD MSP430G2231

Other Parts Discussed in Thread: MSP430G2231, MSP430F2013

Hi Sir,

           I am new to msp430 programming & using TI's MSP Launchpad,having msp430g2231 controller.

I want to send the character A-Z to hyperterminal,i google out one code which i mention below ,& build in ccsV-4 as compiler,the resistor i am mentioning was not found in header file of msp430g2231,what is exact code for msp430g2231 that sends out character strings without using button interrupt.

but it giving few bugs which i have mention below-

 

CODE:-

#include  <msp430g2231.h>

void delay(unsigned int ms)
{
unsigned int i, j;
for (i = 0; i <= ms; i++)
{
for (j = 0; j<=255; j++);
}
}

void main(void)
{
  unsigned int i;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
 
  P3SEL |= 0x06;                            // P3.4,5 = USART0 TXD/RXD
 
  ME1 |= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
 
  UCTL0 |= CHAR;                            // 8-bit character
 
  UTCTL0 |= SSEL0;                          // UCLK = ACLK
  UBR00 = 0x03;                             // 32k/9600 - 3.41
  UBR10 = 0x00;                             //
  UMCTL0 = 0x4A;                            // Modulation
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
 
 
  while (1)

  {
      for (i = 0x41; i <= 0x5A ; i++)
    {
      while (!(IFG1 & UTXIFG0));
     
      TXBUF0 = i;
     
      delay(100);
    }
  }

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

 

**** Build of configuration Debug for project serial ****

C:\Program Files\Texas Instruments\ccsv4\utils\gmake\gmake -k all
'Building file: ../main.c'
'Invoking: Compiler'
"C:/Program Files/Texas Instruments/ccsv4/tools/compiler/msp430/bin/cl430" -vmsp -g --define=__MSP430G2231__ --include_path="C:/Program Files/Texas Instruments/ccsv4/msp430/include" --include_path="C:/Program Files/Texas Instruments/ccsv4/tools/compiler/msp430/include" --diag_warning=225 --printf_support=minimal --preproc_with_compile --preproc_dependency="main.pp"  "../main.c"
"../main.c", line 40: error: identifier "P3SEL" is undefined

>> Compilation failure
"../main.c", line 42: error: identifier "ME1" is undefined
"../main.c", line 42: error: identifier "UTXE0" is undefined
"../main.c", line 42: error: identifier "URXE0" is undefined
"../main.c", line 44: error: identifier "UCTL0" is undefined
"../main.c", line 44: error: identifier "CHAR" is undefined
"../main.c", line 46: error: identifier "UTCTL0" is undefined
"../main.c", line 46: error: identifier "SSEL0" is undefined
"../main.c", line 47: error: identifier "UBR00" is undefined
"../main.c", line 48: error: identifier "UBR10" is undefined
"../main.c", line 49: error: identifier "UMCTL0" is undefined
"../main.c", line 50: error: identifier "SWRST" is undefined
"../main.c", line 58: error: identifier "UTXIFG0" is undefined
"../main.c", line 60: error: identifier "TXBUF0" is undefined
"../main.c", line 66: warning: statement is unreachable
14 errors detected in the compilation of "../main.c".

gmake: *** [main.obj] Error 1
gmake: Target `all' not remade because of errors.
Build complete for project serial

How to remove such bugs.

If it not for msp430g2231,what is exact code for it.

Please reply Please......

 

 

  • Looks like your code is for another device.

    The MSP430G2231 doesn't have  USART and  PORT3.

     

    You can try Timer UART in TI's sample codes.

    http://www.ti.com/lit/zip/slac463

     

  • Hi bhushan,

    if you want to try another example, install Grace on your PC (see http://focus.ti.com/docs/toolsw/folders/print/grace.html?DCMP=Grace&HQS=Other+EM+grace for installation details) and start a new project based on the Software UART example.

    This example comes with a custom 'printf-style' rountine for doing things like this:

    putstr("Hello world.\n\r");

    So, I think this exactly what you are looking for. Take it as a starting point and add your additional code.

    Rgds
    aBUGSworstnightmare

  • hi , I am working with the MSP430G2231 and MSP430F2013, right now i am sending 1 byte with the MSP430F3013 via Serial, but i need to recieve it with the MSP430G2231 and i cant it isnt working, i am doing that with the example. Could you help me?? I am new with this and i really dont understand .Here is the reciever code:


    /******************************************************************************
    * Half Duplex Software UART on the LaunchPad
    *
    * Description: This code provides a simple Bi-Directional Half Duplex
    * Software UART. The timing is dependant on SMCLK, which
    * is set to 1MHz. The transmit function is based off of
    * the example code provided by TI with the LaunchPad.
    * This code was originally created for "NJC's MSP430
    * LaunchPad Blog".
    *
    * Author: Nicholas J. Conn - http://msp430launchpad.com
    * Email: webmaster at msp430launchpad.com
    * Date: 08-17-10
    ******************************************************************************/
     
    #include "msp430g2231.h"
    #include "stdbool.h"

    #define TXD BIT1 // TXD on P1.1
    #define RXD BIT2 // RXD on P1.2

    #define Bit_time 104 // 9600 Baud, SMCLK=1MHz (1MHz/9600)=104
    #define Bit_time_5 52 // Time for half a bit.

    unsigned char BitCnt; // Bit count, used when transmitting byte
    unsigned int TXByte; // Value sent over UART when Transmit() is called
    unsigned int RXByte; // Value recieved once hasRecieved is set

    bool isReceiving; // Status for when the device is receiving
    bool hasReceived; // Lets the program know when a byte is received

    // Function Definitions
    void Transmit(void);

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
     
    BCSCTL1 = CALBC1_1MHZ; // Set range
    DCOCTL = CALDCO_1MHZ; // SMCLK = DCO = 1MHz

    P1SEL |= TXD;
    P1DIR |= TXD;

    P1IES |= RXD; // RXD Hi/lo edge interrupt
    P1IFG &= ~RXD; // Clear RXD (flag) before enabling interrupt
    P1IE |= RXD; // Enable RXD interrupt
     
    isReceiving = false; // Set initial values
    hasReceived = false;
     
    __bis_SR_register(GIE); // interrupts enabled\
    while(1)
    {
    if (hasReceived) // If the device has recieved a value
    {
    hasReceived = false; // Clear the flag
    TXByte = RXByte; // Load the recieved byte into the byte to be transmitted
    Transmit();
    }
    if (~hasReceived) // Loop again if another value has been received
         __bis_SR_register(CPUOFF + GIE);
    // LPM0, the ADC interrupt will wake the processor up. This is so that it does not
    // endlessly loop when no value has been Received.
    }
    }

    // Function Transmits Character from TXByte
    void Transmit()
    {
    while(isReceiving); // Wait for RX completion
       CCTL0 = OUT; // TXD Idle as Mark
       TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode

       BitCnt = 0xA; // Load Bit counter, 8 bits + ST/SP
       CCR0 = TAR; // Initialize compare register
     
       CCR0 += Bit_time; // Set time till first bit
       TXByte |= 0x100; // Add stop bit to TXByte (which is logical 1)
       TXByte = TXByte << 1; // Add start bit (which is logical 0)
     
       CCTL0 = CCIS0 + OUTMOD0 + CCIE; // Set signal, intial value, enable interrupts
       while ( CCTL0 & CCIE ); // Wait for previous TX completion
    }

    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
    isReceiving = true;

    P1IE &= ~RXD; // Disable RXD interrupt
    P1IFG &= ~RXD; // Clear RXD IFG (interrupt flag)

       TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode
       CCR0 = TAR; // Initialize compare register
       CCR0 += Bit_time_5; // Set time till first bit
    CCTL0 = OUTMOD1 + CCIE; // Dissable TX and enable interrupts

    RXByte = 0; // Initialize RXByte
    BitCnt = 0x9; // Load Bit counter, 8 bits + ST
    }

    // Timer A0 interrupt service routine
    #pragma vector=TIMERA0_VECTOR
    __interrupt void Timer_A (void)
    {
    if(!isReceiving)
    {
    CCR0 += Bit_time; // Add Offset to CCR0
    if ( BitCnt == 0) // If all bits TXed
    {
       TACTL = TASSEL_2; // SMCLK, timer off (for power consumption)
    CCTL0 &= ~ CCIE ; // Disable interrupt
    }
    else
    {
    CCTL0 |= OUTMOD2; // Set TX bit to 0
    if (TXByte & 0x01)
    CCTL0 &= ~ OUTMOD2; // If it should be 1, set it to 1
    TXByte = TXByte >> 1;
    BitCnt --;
    }
    }
    else
    {
    CCR0 += Bit_time; // Add Offset to CCR0
    if ( BitCnt == 0)
    {
       TACTL = TASSEL_2; // SMCLK, timer off (for power consumption)
    CCTL0 &= ~ CCIE ; // Disable interrupt

    isReceiving = false;

    P1IFG &= ~RXD; // clear RXD IFG (interrupt flag)
    P1IE |= RXD; // enabled RXD interrupt

    if ( (RXByte & 0x201) == 0x200) // Validate the start and stop bits are correct
    {
    RXByte = RXByte >> 1; // Remove start bit
    RXByte &= 0xFF; // Remove stop bit
    hasReceived = true;
    }
       __bic_SR_register_on_exit(CPUOFF); // Enable CPU so the main while loop continues
    }
    else
    {
    if ( (P1IN & RXD) == RXD) // If bit is set?
    RXByte |= 0x400; // Set the value in the RXByte
    RXByte = RXByte >> 1; // Shift the bits down
    BitCnt --;
    }
    }
    }

    Thanks for your time

**Attention** This is a public forum