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.

uart printing on terminal

Other Parts Discussed in Thread: MSP430F2417hi, how can I make UART of MSP430F2417 to print the characters that I provide through uart , that means It should print the characters that i provide through terminal (hyperterminal) Rupesh IIT kanpur
  • We have USCI channel A UART code examples. Select one with your desired baud rate: http://www.ti.com/lit/zip/slac151

    There is also a nice reference design for the intermediate hardware: http://www.softbaugh.com/downloads/DIR169_Sch_v1_3.pdf

     

  • I tried the following code on MSP2417 controller

    void UARTset(void) //Uses USCI_A0
    {
      P3SEL |= BIT4 + BIT5; /* P3.4, P3.5 UART mode */
      P3DIR |= BIT4;   /* P3.4 - output */
      P3DIR &= BIT5;
      
      UCA0CTL1 |= UCSWRST;   /* disable UART */ //Universal serial communication interface reset)
      UCA0CTL0 = 0x00;
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 0xA;                              // 115200//1.1MHZ
      UCA0BR1 = BAUD1;
      UCA0MCTL = 0;                           // 

      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

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


    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
     
      LEDtypeAON;                                          //just to see whether code jumps to ISR
      while (!(IFG2&UCA0TXIFG));                 // USCI_A0 TX buffer ready?
      UCA0TXBUF = UCA0RXBUF;                     // TX -> RXed character
    }

    void main(void) {
        unsigned char command[10],lastStatus,b;
        // initialize peripherals
        WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
            LEDallOFF;                          //all LED are OFF
            LEDportSET;
           UARTset();
         while(1)
        {
      
         delay_ms(100);
        }
            
     
    }

    so according to the example in the  http://www.ti.com/lit/zip/slac151   MSP430x261x_uscia0_uart_03.c the code should echo the characters I typed on the hyperterminal . even the code does not jump to the ISR . I get the TX interrupt fine and I can print the characters on the terminal but how to recieve it???

    RUPESH

    IITKANPUR

  • Hi RUPESH,

    have you tested the code as is (without modifiying it)?
    Pls note, this MCU example RECEIVES an char from the UART and echos it back to the terminal (hyperterminal). Because of that I'm a little bit confused on your statement regarding the TX interrupt.

    Furthermore some source is missing (i.e. LEDallOFF; what's this); pls provide more info on this. 

    Is Hyperterminal setup correct (9600 - 8N1; 9600baud, 8 data bits, no parity, 1 stopbit)?

    Best regards
    G**kbuster

  • to print a character on the hyper terminal there was a seperate function

    void kputchar(char TXchar)
    {  
     
      while(!(IFG2 & UCA0TXIFG))
           {
            
            }
             
     // wait for TX register to be empty //
        UCA0TXBUF = TXchar; 

    it works fine

    as concern to macros here are they

    #define LEDportSET P1DIR |= 0xF8;
    #define LEDallOFF P1OUT &= ~0xF8;
    #define LEDallON P1OUT |= 0xF8;
    #define LEDpowerON P1OUT |= BIT7;
    #define LEDpowerOFF P1OUT &= ~BIT7;
    #define LEDtypeAON P1OUT |= BIT6;
    #define LEDtypeAOFF P1OUT &= ~BIT6;
    #define LEDtypeBON P1OUT |= BIT5;

    these are just to on off LED. If you have confusion then please let me know rather you please send me the code which just gets characters from uart ?

    thanks

    rupesh

  • Hi Rupesh,

    you already have the code for the UART reveice interrupt. Pls make a modefication to your code posted above and replace

    __bis_SR_register(GIE);       // Enter LPM0, interrupts enabled

    by

    __enable_interrupt();                   // enable all interrupts

    Which example did you use as a staring point? If possible, pls post a 'stripped down' version of your code which only handles MCU initialization, UART receive and transmit (no special makros and stuff like this). This will help others (like me) in fixing the problem.

    rgds
    aBUGSworstnightmare

  • following is the as it is example I am using but it is not echoing any character''

     


    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                    
      { 
        while(1);                               // If calibration constants erased
                                                // do not load, trap CPU!!
      }   
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
      P3SEL = 0x30;                             // P3.4,5 = USCI_A0 TXD/RXD
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 6;                              // 1MHz 9600
      UCA0BR1 = 0;                              // 1MHz 9600
      UCA0MCTL = UCBRF3 + UCOS16;               // Modln UCBRSx=1, over sampling
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

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

    // Echo back RXed character, confirm TX buffer is ready first
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
      while (!(IFG2&UCA0TXIFG));                // USCI_A0 TX buffer ready?
      UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character
    }

  • I replaced it with __enable_interrupt() also but it is not working

**Attention** This is a public forum