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.

CCS/MSP432P401R: Transmit a string as an acknowledgement after recieving data from UART

Part Number: MSP432P401R


Tool/software: Code Composer Studio

hello,

Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

// Echo the received character back
EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
}
}

  • r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    r venkatesh said:

    Part Number: MSP432P401R

    Tool/software: Code Composer Studio

    hello,

    Im trying to send an acknowledgement after recieving the data but am not able to send a string after reception. ive taken my base code from the uart echo example and tried to add a string by removing the EUSCI_A0->RXBUF;in the below code. But only see '@' a lot in the terminal . Can you please help me out with this as im very much new to this .

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    }

    // MSP432P401 Demo - eUSCI_A0 UART echo at 9600 baud using BRCLK = 12MHz
    //
    // Description: This demo echoes back characters received via a PC serial port.
    // SMCLK/ DCO is used as a clock source and the device is put in LPM0
    // The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
    // when the UART is idle and turned on when a receive edge is detected.
    // Note that level shifter hardware is needed to shift between RS232 and MSP
    // voltage levels.
    //
    // The example code shows proper initialization of registers
    // and interrupts to receive and transmit data.
    //
    // MSP432P401
    // -----------------
    // /|\| |
    // | | |
    // --|RST |
    // | |
    // | |
    // | P1.3/UCA0TXD|----> PC (echo)
    // | P1.2/UCA0RXD|<---- PC
    // | |
    //
    // William Goh
    // Texas Instruments Inc.
    // June 2016 (updated) | June 2014 (created)
    // Built with CCSv6.1, IAR, Keil, GCC
    //******************************************************************************
    #include "msp.h"

    int main(void)
    {
    WDT_A->CTL = WDT_A_CTL_PW | // Stop watchdog timer
    WDT_A_CTL_HOLD;

    CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
    CS->CTL0 = 0; // Reset tuning parameters
    CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
    CS->CTL1 = CS_CTL1_SELA_2 | // Select ACLK = REFO
    CS_CTL1_SELS_3 | // SMCLK = DCO
    CS_CTL1_SELM_3; // MCLK = DCO
    CS->KEY = 0; // Lock CS module from unintended accesses

    // Configure UART pins
    P1->SEL0 |= BIT2 | BIT3; // set 2-UART pin as secondary function

    // Configure UART
    EUSCI_A0->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
    EUSCI_A0->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset
    EUSCI_B_CTLW0_SSEL__SMCLK; // Configure eUSCI clock source for SMCLK
    // Baud Rate calculation
    // 12000000/(16*9600) = 78.125
    // Fractional portion = 0.125
    // User's Guide Table 21-4: UCBRSx = 0x10
    // UCBRFx = int ( (78.125-78)*16) = 2
    EUSCI_A0->BRW = 78; // 12000000/16/9600
    EUSCI_A0->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |
    EUSCI_A_MCTLW_OS16;

    EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
    EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag
    EUSCI_A0->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A0 RX interrupt

    // Enable global interrupt
    __enable_irq();

    // Enable eUSCIA0 interrupt in NVIC module
    NVIC->ISER[0] = 1 << ((EUSCIA0_IRQn) & 31);

    // Enable sleep on exit from ISR
    SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;

    // Ensures SLEEPONEXIT occurs immediately
    __DSB();

    // Enter LPM0
    __sleep();
    __no_operation(); // For debugger
    }

    // UART interrupt service routine
    void EUSCIA0_IRQHandler(void)
    {
    if (EUSCI_A0->IFG & EUSCI_A_IFG_RXIFG)
    {
    // Check if the TX buffer is empty first
    while(!(EUSCI_A0->IFG & EUSCI_A_IFG_TXIFG));

    // Echo the received character back
    EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    }
    // EUSCI_A0->TXBUF = 'a';
    }

  • Based on the screenshot or your Terminal it looks like you have selected

    9600 Baud - 7 Data bits - 1 Stop Bit - No Parity - Handshake on RTS

    But Example uses:

    9600 Baud - 8 Data bits - 1 Stop Bit - No Parity - No Handshake

    Esp. the data bits can generate the seen issue.

    Best regards,

     Stefan

    If I had answered to your question, please mark this post as Resolved.

  • Hello Stefen,

    Thank you for your reply.

    As you can see that it has solved the random @ issue now i face an other one. Can you please help me so that the acknowledgement for eg in the code ive used B as acknowledgement. i wanted to use it once per transmission but you can see its continuously  transmitting . below is the code and screenshot. Thanks in advance.

    #include "msp.h"

    int main(void)
    {
    WDT_A->CTL = WDT_A_CTL_PW | // Stop watchdog timer
    WDT_A_CTL_HOLD;

    CS->KEY = CS_KEY_VAL; // Unlock CS module for register access
    CS->CTL0 = 0; // Reset tuning parameters
    CS->CTL0 = CS_CTL0_DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
    CS->CTL1 = CS_CTL1_SELA_2 | // Select ACLK = REFO
    CS_CTL1_SELS_3 | // SMCLK = DCO
    CS_CTL1_SELM_3; // MCLK = DCO
    CS->KEY = 0; // Lock CS module from unintended accesses

    // Configure UART pins
    P1->SEL0 |= BIT2 | BIT3; // set 2-UART pin as secondary function

    // Configure UART
    EUSCI_A0->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
    EUSCI_A0->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset
    EUSCI_B_CTLW0_SSEL__SMCLK; // Configure eUSCI clock source for SMCLK
    // Baud Rate calculation
    // 12000000/(16*9600) = 78.125
    // Fractional portion = 0.125
    // User's Guide Table 21-4: UCBRSx = 0x10
    // UCBRFx = int ( (78.125-78)*16) = 2
    EUSCI_A0->BRW = 78; // 12000000/16/9600
    EUSCI_A0->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |
    EUSCI_A_MCTLW_OS16;

    EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
    EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag
    EUSCI_A0->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A0 RX interrupt

    // Enable global interrupt
    __enable_irq();

    // Enable eUSCIA0 interrupt in NVIC module
    NVIC->ISER[0] = 1 << ((EUSCIA0_IRQn) & 31);

    // Enable sleep on exit from ISR
    SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;

    // Ensures SLEEPONEXIT occurs immediately
    __DSB();

    // Enter LPM0
    __sleep();
    __no_operation(); // For debugger
    }

    // UART interrupt service routine
    void EUSCIA0_IRQHandler(void)
    {
    // if (EUSCI_A0->IFG & EUSCI_A_IFG_RXIFG)
    // {
    // Check if the TX buffer is empty first
    // while(!(EUSCI_A0->IFG & EUSCI_A_IFG_TXIFG));

    // Echo the received character back
    //EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
    // }
    EUSCI_A0->TXBUF = 'B';
    }

  • Hi,

    you get continuous calls into the UART interrupt service handler because the RX interrupt flag does not get cleared.

    This flag gets cleared automatically by reading the EUSCI_A0->RXBUF or by clearing the flag.

    Note: before putting data into the TXBUF register it is a good practice to also check if the buffer is free.

    So the simplified interrupt service handler function just sending back a fixed char once any character is received can look like this:

    // UART interrupt service routine
    void EUSCIA0_IRQHandler(void)
    {
      volatile  uint8_t temp;   // volatile temp register to avoid optimizing
    
      if (EUSCI_A0->IFG & EUSCI_A_IFG_RXIFG)
      {
        // Either read RXBUF or clear RX IFG
        temp = EUSCI_A0->RXBUF;
        //EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG;
    
        //Check if the TX buffer is empty first
        while(!(EUSCI_A0->IFG & EUSCI_A_IFG_TXIFG));
    
        //EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
        EUSCI_A0->TXBUF = 'B';
      }
    }

  • Thanks for the reply stefen. this has solved my issue. Now im able send and receive acknowledgement. Thnaks a ton

**Attention** This is a public forum