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.

help with hello world

Other Parts Discussed in Thread: MSP430G2553, MSP430F2274

Hi All,

I can not send a string 'hello world', I'm using eZ430-RF2500.
with hyper terminal setting 8N1.
Could someone help me? (This is my first code)

 

#include <msp430.h>

const char string1[] = { "Hello World\r\n" };
unsigned int i;

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
   if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
  {
    while(1);                               // do not load, trap CPU!!
  }
  DCOCTL = 0;                               // Select lowest DCOx and MODx settings
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
  DCOCTL = CALDCO_1MHZ;
  P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 = 0x104;                          // 1MHz 9600
  UCA0BR1 = 0;                              // 1MHz 9600
  UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0TXIE;                          // Enable USCI_A0 RX interrupt

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
}

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
  UCA0TXBUF = string1[i++];                 // TX next character

  if (i == sizeof string1 - 1)              // TX over?
    IE2 &= ~UCA0TXIE;                       // Disable USCI_A0 TX interrupt
}

  • Manuel Corini said:
    UCA0BR0 = 0x104; // 1MHz 9600

    At a quick look; your baudrate setting is incorrect. Use decimal 104 instead of hex or 0x68.

  • hey,

    As leo mentioned all u need to do is to turn your hex 104 to decimal 104. For furthur understanding of ho to set baud rate refer this link.

    Cheers,

  • thank you.

    I changed the code, but now stamp only the first letter of hello world, that is H and not the entire string.

    #include <msp430.h>
    
    const char string1[] = { "Hello World\r\n" };
    unsigned int i;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
       if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 0x6d;                           // 1,05MHz/ 9600= 109,3 che in esadecimal è 6d
      UCA0BR1 = 0;                              // 1MHz 9600
      UCA0MCTL = UCBRS2;                        // Modulation UCBRSx = 1
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0TXIE;                          // Enable USCI_A0 RX interrupt
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    }
    
    #pragma vector=USCIAB0TX_VECTOR
    __interrupt void USCI0TX_ISR(void)
    {
      UCA0TXBUF = string1[i++];                 // TX next character
    
      if (i == sizeof string1 - 1)              // TX over?
        IE2 &= ~UCA0TXIE;                       // Disable USCI_A0 TX interrupt
    }
    
    

  • Manuel Corini said:
    unsigned int i;

    Change to: volatile unsigned int i = 0;

    Manuel Corini said:
    if (i == sizeof string1 - 1)

    I would write here: if (i >= (sizeof(string1) – 1))

    And you could use the debugger to see what happens!


  • Manuel Corini said:
    #pragma vector=USCIAB0TX_VECTOR __interrupt void USCI0TX_ISR(void) { UCA0TXBUF = string1[i++]; // TX next character if (i == sizeof string1 - 1) // TX over? IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt }



    Your out put is right u should only get H. COz on leaving interrupt you were diabling interrupts on Tx.

    which mean MSp will transmit H and finds that  UCA0TXIE is tolleged. So, the fix is-->

    replace this instruction with, IFG2 = UCA0TXIFG;

    Cheers,
    Sri.

  • I'm sorry but I do not understand what line of code should I change with IFG2 = UCA0TXIFG;

  • Replace this line.

    Manuel Corini said:
    IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt


    This line, Here you are disabling furthur interrupts "IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupts"
    U Just need to clear the interrupt flag UCA0TXIFG not UCA0TXIE.

    UCA0TXIE  = 1/0 enables/disables  interrupts in UART communication
    UCA0TXIFG   1/0 set/clared interrupt flag  for Transmission phase of UART communication.

    just a small tip:

    Any time you were working with Interrupts, before leaving ISR you clar the corresponding IFG flag.
    Ex: Port interrupts 
          P1IE = 0xFF // Interrupts enabled on all port pins
          when ever there is a interrupt of P1, the bit corresponding to the pin is set in p1IFG register.
          On leaving port1 ISR you clear that bit of P1IFG.
    there is one exenption for this (TA1CCRO interrupt) u willl know this when u deal with timers.

    Cheers.
       

  • thanks for your patience.
    I made ​​the change but now on hyper terminal I print all H:
    HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH.

    #include <msp430.h>
    
    const char string1[] = { "Hello World\r\n" };
    volatile unsigned int i=0;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
       if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 0x6d;                           // 1,05MHz/ 9600= 109,3 che in esadecimale è 6d
      UCA0BR1 = 0;                              // 1MHz 9600
      UCA0MCTL = UCBRS2;                        // Modulation UCBRSx = 1
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0TXIE;                          // Enable USCI_A0 RX interrupt
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    }
    
    #pragma vector=USCIAB0TX_VECTOR
    __interrupt void USCI0TX_ISR(void)
    {
    	while (!(IFG2 & UCA0TXIFG));	            // USART0 TX buffer ready?
    		UCA0TXBUF = string1[i++];
      if (i >= sizeof string1 - 1)              // TX over?
        IE2 &= ~UCA0TXIFG;                       // Disable USCI_A0 TX interrupt
    }
    

    then I would ask a 'thing
    how do I add the following libraries in the project:?

    #include "virtual_com_cmds.h"

    #include "bsp.h"

  • It should work!

    Manuel Corini said:
    while (!(IFG2 & UCA0TXIFG)); // USART0 TX buffer ready?

    But this line you can remove.

    Manuel Corini said:

    how do I add the following libraries in the project:?

    #include "virtual_com_cmds.h"

    #include "bsp.h"

    Add these includes in the source file and add or link the corresponding libraries to the project.

  • With the code like this:

    #include <msp430.h>
    
    const char string1[] = { "Hello World\r\n" };
    volatile unsigned int i=0;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    
      if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
    
      UCA0CTL1 |= UCSWRST;						// **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
      P1SEL = BIT1 | BIT2;                      // P1.1,2 = USCI_A0 RXD/TXD
      P1SEL2 = BIT1 | BIT2;                     // P1.1,2 = USCI_A0 RXD/TXD
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
      IE2 |= UCA0TXIE;                          // Enable USCI_A0 RX interrupt
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    }
    
    #pragma vector=USCIAB0TX_VECTOR
    __interrupt void USCI0TX_ISR(void)
    {
      UCA0TXBUF = string1[i++];				// Write next char (clears UCA0TXIFG automatically)
    
      if (i >= sizeof string1 - 1)            // TX over?
        IE2 &= ~UCA0TXIE;                   // Disable USCI_A0 TX interrupt
    }
    

    It works for me on an MSP-EXP430G2 launchpad with an msp430g2553. I get the full message "Hello World" in the terminal window.

    What compiler are you using to build your code?

  • I do not know, where can I see?

  • Are you using Code Composer Studio (CCS), IAR workbench or something else?

  • HI Corini,

    My apologies, your earlier code was absolutely fine, I just over looked the idea that once UCA0TXBUF is dumped UCA0TXIFG is cleared automatically. I have ran u r cde and it did run well so sorry for mis leading you for a while. I should have tried your code before commenting any way.

    Once you have loaded your code.
    in CCS--> 
    go to View>>other>>Terminal>>terminal.

     a termnal concol opensup, just like Problems and search .

    now clcik on that hover over that yellow notepad like button (settings) and click.

    My Launchpad is connected to com8 (automatically detected) so should yours. 
    After loading the code. Open the terminal make necessary settings and click on conncect button.
    If you do not see hello worlld. Press and hold reset button for 10 seconds and then release. Bingo.

    Apologies agin.
    cheers.

  • Ok, the code now I can not prove it because the circuit does not have it at home, but at the university. That code, however, works on the launchpad, not on my eZ430 RF2500.
    Should I make changes on pins, or work?

    #include <msp430.h>
    
    const char string1[] = { "Hello World\r\n" };
    volatile unsigned int i=0;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0TXIE; // Enable USCI_A0 RX interrupt __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled } #pragma vector=USCIAB0TX_VECTOR __interrupt void USCI0TX_ISR(void) { UCA0TXBUF = string1[i++]; // Write next char (clears UCA0TXIFG automatically) if (i >= sizeof string1 - 1) // TX over? IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt }

  • Yes you have to change pins. and I think you did so, in this code. 


    for msp430g2553 UART pins are P1.1 & P1.2
    for msp430f2274 UART pins are  P3.4 & P3.5

    this code might work. I donot have one f2274 handy to check for you. 

    Also I think you have to select modulation scheme from Modulation control register.

  • Hello sri,
    I want to thank you, the code works. You made me a beautiful picture in front of the professor.
    But now I have a new problem, I built the following program compiles without errors, but I do not write hello world, I do not understand why, though I copied the function TXString on CCS; you can give it a try, thank you.

    #include <msp430.h>
    
    void TXString(char*string1,int lenght);
    volatile unsigned int i=0;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0TXIE;                          // Enable USCI_A0 TX interrupt
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    
    
      TXString("Hello world\\n",12);
    }
    
    
    void TXString( char* string1, int lenght )
    {
      int pointer=0;
      for( pointer = 0; pointer < lenght; pointer++)
      {
    	  volatile int i;
    	  UCA0TXBUF = string1[pointer];
    	  while (!(IFG2 & UCA0TXIFG));
    
      }
    }
    

  • You're enabling the USCI TX interrupt and setting GIE. When UCA0TXIFG gets set the MCU will try to jump to the USCIAB0TX_VECTOR ISR, but it doesn't exist.

  • then it should work if I delete this line?

      __bis_SR_register(LPM0_bits + GIE);      

    the code becomes:

    #include <msp430.h>
    
    void TXString(char*string1,int lenght);
    volatile unsigned int i=0;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0TXIE;                          // Enable USCI_A0 TX interrupt
    
      TXString("Hello world\\n",12);
    }
    
    
    void TXString( char* string1, int lenght )
    {
      int pointer=0;
      for( pointer = 0; pointer < lenght; pointer++)
      {
    	  volatile int i;
    	  UCA0TXBUF = string1[pointer];
    	  while (!(IFG2 & UCA0TXIFG));
    
      }
    }
    

  • Manuel Corini said:

    then it should work if I delete this line?

      __bis_SR_register(LPM0_bits + GIE);      

    No, that would be a bad idea. If you delete that whole line the MCU won't enter low power mode, meaning that there's nothing to stop execution continuing past the end of main().

    You still need to enter low power mode, just without setting GIE or UCA0TXIE.

  • If I understand it I have to remove one of the two or GIE or UCA0TXIE

    At this point, I'm not using an interrupt, write the string to use only the function TXString, I can delete them both?

    #include <msp430.h>
    
    void TXString(char*string1,int lenght);
    volatile unsigned int i=0;
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      //    delete?????IE2 |= UCA0TXIE;




    __bis_SR_register(LPM0_bits); // Enter LPM0 TXString("Hello world\\n",12); } void TXString( char* string1, int lenght ) { int pointer=0; for( pointer = 0; pointer < lenght; pointer++) { volatile int i; UCA0TXBUF = string1[pointer]; while (!(IFG2 & UCA0TXIFG)); } }

  • Hey Glad to hear that, 
    This code is working fine with msp430g2553.

    #include <msp430.h>
    
    #define g2553
    //#define test1
    void TXString(char*string1,int lenght);
    volatile unsigned int i=0;
    
    #ifdef test1
    const char string1[] = { "Hello World\r\n" };
    #endif
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
    
    #ifdef g2553
      P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
      P1SEL2 = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
    #endif
    
      UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
    
    #ifndef g2553
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
    #endif
    
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    #ifdef test1
      IE2 |= UCA0TXIE;                          // Enable USCI_A0 TX interrupt
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    #endif
    
    #ifndef test1
      TXString("Hello world\r\n",12);
    #endif
    }
    
    #ifdef test1
    #pragma vector=USCIAB0TX_VECTOR
    __interrupt void USCI0TX_ISR(void)
    {
      UCA0TXBUF = string1[i++];                 // TX next character
    
      if (i == sizeof string1 - 1)              // TX over?
        IE2 &= ~UCA0TXIE;                       // Disable USCI_A0 TX interrupt
    }
    #endif
    
    #ifndef test1
    void TXString( char* string1, int lenght )
    {
      int pointer=0;
      for( pointer = 0; pointer < lenght; pointer++)
      {
          volatile int i;
          UCA0TXBUF = string1[pointer];
          while (!(IFG2 & UCA0TXIFG));
      }
    }
    #endif
    

    chers

  • Hi Sri,

    Some little corrections;

    sri-sri said:
    #ifndef test1 TXString("Hello world\r\n",12); #endif

    The Return (\r) can be omitted will be automatically added by HyperTerminal, otherwise the length needs to be 13.

    void TXString( char* string1, int lenght )
    {
      int pointer=0;
      for(; pointer < lenght; pointer++)
      {
    //      volatile int i;
          UCA0TXBUF = string1[pointer];
          while (!(IFG2 & UCA0TXIFG));
      }
    
      while (*string1 != 0)
      {
          while (!(IFG2 & UCA0TXIFG));
    	  UCA0TXBUF = *string1++;
      }
    }
    

    The volatile int i; can removed.

    In the for() you don’t need to clear pointer while it’s already done.

    Another way to output a variable length of string is the while example.

  • Cool Leo,
    Thank you so much.
    Cheers! :) 

  • Hi,

    The string hello world, is sent by  'interrupts or function TXString?

  • By function Manuel.

    The code which I have posted has ISR but been commented out by commands #ifdef.

    So I mean to say your code works. cheers.

  • Hello sri,
    I tried your code, but it does not work; because with makeup ifdef and ifndef,
    the code becomes equal to that of my previously posted.

    The problem could be GIE, but I do not know how to change it.

    #include <msp430.h>
    
    void TXString(char*string1,int lenght);
    volatile unsigned int i=0;
    
    int main(void)
    {
    	 WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    	  if (CALBC1_1MHZ==0xFF)                   // If calibration constant erased
    	  {
    	    while(1);                               // do not load, trap CPU!!
    	  }
    	  DCOCTL = 0;                               // Select lowest DCOx and MODx settings
    	  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
    	  DCOCTL = CALDCO_1MHZ;
    	  UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
    	  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
    	  UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
    	  UCA0BR1 = 0;                              // 1MHz 9600
    	  P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
    	  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    	  IE2 |= UCA0TXIE;                          // Enable USCI_A0 TX interrupt
    	  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
    
      TXString("Hello world\n",12);
    
    }
    
    void TXString( char* string1, int lenght )
    {
      int pointer=0;
      for(; pointer < lenght; pointer++)
      {
          UCA0TXBUF = string1[pointer];
          while (!(IFG2 & UCA0TXIFG));
      }
      while (*string1 != 0)
      {
          while (!(IFG2 & UCA0TXIFG));
          UCA0TXBUF = *string1++;
      }
    }
    
    

  • A little bit too many options for you. I cleaned it up didn’t test it but guess it will work. Without interrupts, just calling TXString().

    #include <msp430.h>
    
    void TXString (char* string1);
    
    void main (void)
    {
    	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    	if (CALBC1_1MHZ==0xFF)                    // If calibration constant erased
    	{
    		while (1);                            // do not load, trap CPU!!
    	}
    	DCOCTL = 0;                               // Select lowest DCOx and MODx settings
    	BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
    	DCOCTL = CALDCO_1MHZ;
    	UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
    	UCA0CTL1 |= UCSSEL_2;                     // SMCLK
    	UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
    	UCA0BR1 = 0;                              // 1MHz 9600
    	P3SEL = BIT4 | BIT5;                      // P3.4,5 = USCI_A0 TXD/RXD
    	UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    	TXString("Hello world\n");
    
    	while (1);
    }
    
    void TXString (char* string1)
    {
    	while (*string1 != 0)
    	{
    		while (!(IFG2 & UCA0TXIFG));
    		UCA0TXBUF = *string1++;
    	}
    }
    

  • Manuel Corini said:
    I tried your code, but it does not work; because with makeup ifdef and ifndef,
    the code becomes equal to that of my previously posted.



    No it does not.

    Ifdef statement only facilitate you to turn on those you need. well any way I have tied up the code here for you and posted along with the result.AHH aslo i have added the leo's modifications cheers.

    #include <msp430.h>
    void TXString(char*string1,int lenght);
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ==0xFF)   while(1);        // If calibration constant erased Lock the code here.
      DCOCTL  = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL  = CALDCO_1MHZ;
      P1SEL   = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
      P1SEL2  = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
      UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
      UCA0BR1 = 0;                              // 1MHz 9600
    //  P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      TXString("Hello world\\n",12);
    }
    void TXString( char* string1, int lenght )
    { int pointer = 0;
      for( ; pointer < lenght; pointer++)
      {   UCA0TXBUF = string1[pointer];
          while (!(IFG2 & UCA0TXIFG));
      }
      //Leo modification
      while (*string1 != 0)
      {    while (!(IFG2 & UCA0TXIFG));
           UCA0TXBUF = *string1++;
      }
    }
    

  • One point to note, Ihave tested the code with msp430g2553 so I ahve added  below lines for Msp430g2553

      P1SEL   = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
      P1SEL2  = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
    
    and commented out this line as this is for msp430Fxxxx // P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD

    cheers :)

  • Thank you, tomorrow I try to the lab and let you know

  • thanks sri, thanks Leo, thank you Robert. The code works puts it below. I would like to ask one thing: I tried to set as 115200 baud, with 1 MHz setting UCA0BR0 = 9 by the book; but the code does not write anything. If there is some limitation to, since I'm using a RF2500 eZ430 MSP430F2274 ?

    #include <msp430.h>
    
    void TXString (char* string1);
    
    void main (void)
    {
    	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    	if (CALBC1_1MHZ==0xFF)                    // If calibration constant erased
    	{
    		while (1);                            // do not load, trap CPU!!
    	}
    	DCOCTL = 0;                               // Select lowest DCOx and MODx settings
    	BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
    	DCOCTL = CALDCO_1MHZ;
    	UCA0CTL1 |= UCSWRST;                      // **Initialize USCI state machine**
    	UCA0CTL1 |= UCSSEL_2;                     // SMCLK
    	UCA0BR0 = 104;                            // 1MHz/9600= 104.1666
    	UCA0BR1 = 0;                              // 1MHz 9600
    	P3SEL = BIT4 | BIT5;                      // P3.4,5 = USCI_A0 TXD/RXD
    	UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    	TXString("Hello world\n");
    
    	while (1);
    }
    
    void TXString (char* string1)
    {
    	while (*string1 != 0)
    	{
    		while (!(IFG2 & UCA0TXIFG));
    		UCA0TXBUF = *string1++;
    	}
    }
    
  • pocho said:
    thanks sri, thanks Leo, thank you Robert. The code works puts it below. I would like to ask one thing: I tried to set as 115200 baud, with 1 MHz setting UCA0BR0 = 9 by the book; but the code does not write anything. If there is some limitation to, since I'm using a RF2500 eZ430 MSP430F2274 ?

    That's a limitation of the eZ430 - the UART backchannel runs at a fixed 9600 baud. This is stated in section 6 of the ez430 hardware user manual.

**Attention** This is a public forum