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.

MSP430FR6047: Error in UART Data transmitted

Part Number: MSP430FR6047

Hi, I am trying to send the capture data via UART, I am using the same method that is used in "MSP430FR6047EVM_USS_Water_Demo" app. I am trying to implement this in "FR6047_USSSWLib_template_example", At a baud rate 4800. However after configuring UART transmission as in "MSP430FR6047EVM_USS_Water_Demo", I am getting dtof results fine but the capture data in gibberish. 

Is the UART setting in MSP430FR6047EVM_USS_Water_Demo is different from FR6047_USSSWLib_template_example?

My UART configuration is as follows.

	// GPIO Configuration for UART mode
    P1SEL0 |= (BIT2 | BIT3);
    P1SEL1 &= ~(BIT2 | BIT3);

    // Configure USCI_A0 for UART mode, 8-bit data, 1 stop bit
    UCA1CTLW0 = UCSWRST;                    // Put eUSCI in reset
    UCA1CTLW0 |= UCSSEL__SMCLK;             // CLK = SMCLK

//    // For BRCLK = SMCLK = 8MHz, and Baud rate = 115200 (See UG)
//    UCA1BRW = 4;
//    // UCBRSx (bits 7-4) = 0x55, UCBRFx (bits 3-1) = 5, UCOS16 (bit 0) = 1
//    UCA1MCTLW = 0x5551;

    // Baud Rate Setting 115200
      // Use Table 30-5 in Family User Guide
//      UCA0BR0 = 8;
//      UCA0BR1 = 0;
//      UCA0MCTLW |= UCOS16 | UCBRF_10 | 0xF700;   //0xF700 is UCBRSx = 0xF7

    // Baud Rate Setting SMCLK 9600
    // Use Table 30-5 in Family User Guide
      UCA1BR0 = 104;
      UCA1BR1 = 0;
      UCA1MCTLW |= UCOS16 | UCBRF_2 | 0xD600;   //0xD600 is UCBRSx = 0xD6


    UCA1CTLW0 &= ~UCSWRST;                 // release from reset


    //--SETUP IRQ A1 RXIFG
           UCA1IE |= UCRXIE;                       // Enable USCI_A0 RX interrupt
           __enable_interrupt();

This what I get when I try to get capture data

´üÿûÿþÿ²Uª>Àÿÿÿÿÿÿÿÿþÿÿÿýÿþÿýÿþÿýÿüÿþÿüÿýÿýÿúÿýÿýÿüÿûÿýÿûÿþÿûÿ�2Uª>Àÿþÿüÿûÿüÿüÿýÿûÿþÿüÿüÿþÿüÿüÿüÿûÿüÿþÿúÿÿÿýÿûÿûÿûÿýÿüÿüÿb6Uª>ÀÿüÿýÿüÿúÿúÿýÿüÿûÿüÿþÿüÿúÿýÿûÿýÿûÿüÿÿÿûÿüÿüÿüÿúÿüÿúÿüÿV6Uª>ÀÿþÿúÿúÿüÿýÿûÿûÿüÿýÿúÿýÿþÿúÿûÿüÿúÿúÿþÿûÿýÿúÿüÿûÿûÿûÿýÿR6Uª>Àÿµûÿüÿýÿ²Uª>Áÿÿÿÿÿÿÿÿþÿþÿþÿýÿýÿþÿüÿþÿûÿüÿüÿýÿýÿüÿüÿþÿüÿüÿüÿþÿûÿ‚2Uª>Áÿûÿþÿúÿüÿüÿýÿûÿüÿýÿüÿúÿþÿûÿþÿüÿûÿûÿüÿüÿýÿüÿûÿüÿüÿûÿüÿ\6Uª>ÁÿþÿûÿüÿùÿýÿúÿýÿüÿüÿûÿûÿûÿýÿûÿýÿúÿúÿÿÿüÿýÿúÿûÿûÿüÿúÿþÿS6Uª>ÁÿüÿûÿüÿüÿûÿüÿþÿùÿüÿüÿøÿþÿûÿýÿûÿüÿüÿüÿûÿþÿùÿûÿúÿûÿÿÿüÿT6Uª>Á

Any help is appreciated, thanks.
Joshua

  • I think we need to see how you are sending the data? An implementation that does not wait for TXBuf to clear can clobber it. Did you check it with a scope to verify that the baud rate was correct?

  • Hi Joshua,

    When you say you are trying to get the capture information via UART like in the Water_Demo, do you just mean the dToF, aToF, VFR... etc? This is demonstrated in the template example, which already includes the functionality to send this info out via UART. To see this data you should just need to program the example project to your device, and probe the UART pins on the EVM. Is there a reason you are avoiding using the UART functionality included in the template example?

  • Hi Keith,

    Thank you for your quick response. I following same procedure as in Water_Demo to send the USS ADC captures (UPS and DNS captures) . I am using following functions from the demo code.

    extern void CommandHandler_transmitCaptures(Packet_t *packet);


    extern void CommandHandler_transmitCapturePackages(Packet_t *packet,
    uint8_t id,
    uint8_t numOfPcks,
    int8_t finalPckLenght,
    uint8_t* pCap);

    extern void CommandHandler_transmitPacket(Packet_t *packet);

    extern void Comm_writePacket(const Packet_t *packet);

    extern void Comm_writeBuffer(const uint8_t *sourceBuffer, uint16_t sourceLength);

    I have created a uart.c as shown below, when the MSP receives UART code "a" "/n", it starts the transmission. by calling the function CommandHandler_transmitCaptures.

    /*
     * uart.c
     *
     *  Created on: 23 Jan 2024
     *      Author: AntonyJoshua
     */
    
    #include "protocol/uart.h"
    #include <intrinsics.h>
    #include <stdint.h>
    #include "msp430.h"
    #include "main.h"
    #include "protocol/packet.h"
    #include "protocol/uart.h"
    
    
    extern void CommandHandler_transmitCaptures(Packet_t *packet);
    extern void CommandHandler_transmitCapturePackages(Packet_t *packet,
                                                       uint8_t id,
                                                       uint8_t numOfPcks,
                                                       int8_t finalPckLenght,
                                                       uint8_t* pCap);
    
    extern void CommandHandler_transmitPacket(Packet_t *packet);
    extern void Comm_writePacket(const Packet_t *packet);
    extern void Comm_writeBuffer(const uint8_t *sourceBuffer, uint16_t sourceLength);
    
    //extern uint16_t g_ui16UARTTransmitBytesLeft;
    
    
    
    #define BUFFER_SIZE 27
    
    #define COMMAND_HANDLER_UPS_DNS_CAP_MAX_CAP_SIZE            27
    
    /*  USS GUI Design Center Plotting variable length packet
    *******************************************************************************/
    #define COMMAND_HANDLER_CAPTURE_PACKET_SIZE                 60
    #define COMMAND_HANDLER_UPS_ADC_CAPTURE_ID                  0xC0
    #define COMMAND_HANDLER_DNS_ADC_CAPTURE_ID                  0xC1
    
    /*******************************************************************************
    *  USS GUI Design Center Plotting packet
    *******************************************************************************/
    #define COMMAND_HANDLER_PLOT_PACKET_SIZE                    11
    #define COMMAND_HANDLER_PLOT_DTOF_ID                        0xB0
    #define COMMAND_HANDLER_PLOT_ABS_UPS_ID                     0xB1
    #define COMMAND_HANDLER_PLOT_ABS_DNS_ID                     0xB2
    #define COMMAND_HANDLER_PLOT_VOL_ID                         0xB3
    #define COMMAND_HANDLER_PLOT_ADC_UPS_STRT_STP_PACKS_ID      0xB4
    #define COMMAND_HANDLER_PLOT_ADC_DNS_STRT_STP_PACKS_ID      0xB5
    #define COMMAND_HANDLER_PLOT_GENERIC_PLOT_ID                0xB6
    #define COMMAND_HANDLER_PLOT_ADVANCED_GENERIC_PLOT_ID       0xB7
    #define COMMAND_HANDLER_PLOT_ADC_START_TX                   true
    #define COMMAND_HANDLER_PLOT_ADC_STOP_TX                    false
    // Command 0xB6-0xBF  are reserved for future plotting commands
    
    /*******************************************************************************
    * Define used to identify packet as USS GUI Desing Center packet
    *******************************************************************************/
    #define COMMAND_HANDLER_USS_GUI_ID_BYTE                     0x04
    #define COMMAND_HANDLER_WRITE_CMD                           true
    #define COMM_TX_BUFF_SZ  (800)
    #define EUSCI_A_UART_TRANSMIT_INTERRUPT                     UCTXIE
    
    uint8_t Comm_transmitBuffer[COMM_TX_BUFF_SZ];
    
    uint8_t uss_param_uart[BUFFER_SIZE];
    uint16_t UartRcvBufIndex = 0;
    
    #if defined(__TI_COMPILER_VERSION__)
    #pragma PERSISTENT(gstxPacket)
    #define __persistent
    #elif defined (__IAR_SYSTEMS_ICC__)
    #else
    #error Compiler not supported!
    #endif
    
    /*** GLOBAL VARIABLES ***/
    __persistent Packet_t gstxPacket = {0};
    
    
    //*****************************************************************************
    //
    //! var g_pUARTPort stores a pointer to the UART port configuration
    //! structure that was passed to the UART_openPort function.  The UART
    //! driver does not modify this structure.
    //
    //*****************************************************************************
    const tUARTPort *g_pUARTPort;
    
    //*****************************************************************************
    //
    //! var g_pUARTTransmitPtr stores a pointer to the current byte to transmit.
    //
    //*****************************************************************************
    volatile const uint8_t *g_pUARTTransmitPtr;
    
    //*****************************************************************************
    //
    //! var g_ui16UARTTransmitBytesLeft stores how many bytes remain to be sent
    //! in the current transmission.
    //
    //*****************************************************************************
    volatile uint16_t g_ui16UARTTransmitBytesLeft;
    
    //*****************************************************************************
    //
    //! var g_UARTStatus stores the current status of the UART port driver.
    //
    //*****************************************************************************
    volatile uint8_t g_UARTStatus;
    
    //void UART_openPort(const tUARTPort *pPort)
    //{
    //    UART_closePort();
    //    g_pUARTPort = pPort;
    //
    //    EUSCI_A_UART_init(
    //            UART__EUSCI_A_PERIPHERAL,
    //            (EUSCI_A_UART_initParam*)&(g_pUARTPort->peripheralParameters)
    //        );
    //    EUSCI_A_UART_enable(UART__EUSCI_A_PERIPHERAL);
    //    EUSCI_A_UART_clearInterrupt(
    //            UART__EUSCI_A_PERIPHERAL,
    //            EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG
    //        );
    //    EUSCI_A_UART_enableInterrupt(
    //            UART__EUSCI_A_PERIPHERAL,
    //            EUSCI_A_UART_RECEIVE_INTERRUPT
    //        );
    //
    //    g_UARTStatus = eUARTIsIdle;
    //}
    //
    //void UART_closePort(void)
    //{
    //    g_UARTStatus = eUARTIsClosed;
    //    EUSCI_A_UART_disable(UART__EUSCI_A_PERIPHERAL);
    //}
    
    uint8_t UART_getPortStatus(void)
    {
        return g_UARTStatus;
    }
    
    void UART_transmitBuffer(const uint8_t *pBuffer, uint16_t ui16Length)
    {
        g_UARTStatus = eUARTIsIdle;
    
        if (g_UARTStatus == eUARTIsClosed)
        {
            return;
        }
    
        //
        // Before transmitting, safely wait for
        // current operations to finish
        //
    #if (UART__LPMx_bits>0)
        while (1)
        {
            __bic_SR_register(GIE);
            if (g_UARTStatus != eUARTIsIdle)
            {
                __bis_SR_register(UART__LPMx_bits | GIE);
            }
            else
            {
                __bis_SR_register(GIE);
                break;
            }
        };
    #else
        while(g_UARTStatus != eUARTIsIdle);
    #endif
    
        g_pUARTTransmitPtr = pBuffer;
        g_ui16UARTTransmitBytesLeft = ui16Length;
        g_UARTStatus = eUARTIsTransmitting;
        EUSCI_A_UART_enableInterrupt(
                UART__EUSCI_A_PERIPHERAL,
                EUSCI_A_UART_TRANSMIT_INTERRUPT
            );
    }
    
    //extern void UART_transmitByteImmediately(uint8_t ui8Data)
    //{
    //    while(!(EUSCI_A_UART_getInterruptStatus(
    //                    UART__EUSCI_A_PERIPHERAL,
    //                    EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG
    //                )
    //            ));
    //    EUSCI_A_UART_transmitData(UART__EUSCI_A_PERIPHERAL, ui8Data);
    //};
    
    //*****************************************************************************
    //
    //! UART Interrupt Service Routine
    //
    //*****************************************************************************
    
    #pragma vector=EUSCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    {
        switch(__even_in_range(UCA1IV, USCI_UART_UCTXCPTIFG))
        {
            case USCI_NONE: break;
            case USCI_UART_UCRXIFG:
    
                uss_param_uart[UartRcvBufIndex++] = UCA1RXBUF; //fetch byte and store
    
    
               if (UCA1RXBUF == '\n')
               {
    
                   if(uss_param_uart[0]=='a')
                   {
                       CommandHandler_transmitCaptures(&gstxPacket);
                   }
    
    
                   UartRcvBufIndex = 0; // Clearing the array index 
                   flag=0;
               }
    
                __no_operation();
                break;
    
            case USCI_UART_UCTXIFG:
              EUSCI_A_UART_transmitData(
                        UART__EUSCI_A_PERIPHERAL,
                       *(g_pUARTTransmitPtr++)
                  );
    
                g_ui16UARTTransmitBytesLeft--;
    
                if (g_ui16UARTTransmitBytesLeft == 0)
                {
                    EUSCI_A_UART_disableInterrupt(
                            UART__EUSCI_A_PERIPHERAL,
                            EUSCI_A_UART_TRANSMIT_INTERRUPT
                        );
                    g_UARTStatus = eUARTIsIdle;
                    __bic_SR_register_on_exit(UART__LPMx_bits);
                }
                break;
            case USCI_UART_UCSTTIFG: break;
            case USCI_UART_UCTXCPTIFG: break;
            default: break;
        }
    }
    
    
    // Function to send ADC Capture
    
    void CommandHandler_transmitCaptures(Packet_t *txPacket)
    {
        // Calculate number of packets that will need to be sent
        // Each ADC capture packet can hold up to 27 captures
        uint16_t updnsCaptureSize = gUssSWConfig.captureConfig->sampleSize;
        uint8_t numOfPcks = (uint8_t)(updnsCaptureSize/ COMMAND_HANDLER_UPS_DNS_CAP_MAX_CAP_SIZE);
        int8_t finalPckLength = (uint8_t)(updnsCaptureSize % COMMAND_HANDLER_UPS_DNS_CAP_MAX_CAP_SIZE);
        // Calculate number of bytes in each capture
        uint8_t* pUPSCap = (uint8_t*)(USS_getUPSPtr(&gUssSWConfig));
        uint8_t* pDNSCap = (uint8_t*)(USS_getDNSPtr(&gUssSWConfig));
    
        if( finalPckLength > 0 )
        {
            numOfPcks++;
        }
        else
        {
            finalPckLength = COMMAND_HANDLER_UPS_DNS_CAP_MAX_CAP_SIZE;
        }
    
    
        CommandHandler_transmitCapturePackages(txPacket,
                COMMAND_HANDLER_UPS_ADC_CAPTURE_ID,
                numOfPcks,
                finalPckLength, pUPSCap);
    
        CommandHandler_transmitCapturePackages(txPacket,
                COMMAND_HANDLER_DNS_ADC_CAPTURE_ID,
                numOfPcks,
                finalPckLength, pDNSCap);
    
    }
    
    //Transmitting capture packages
    void CommandHandler_transmitCapturePackages(Packet_t *txPacket,
                uint8_t id, uint8_t numOfPcks, int8_t finalPckLength,
                uint8_t* pCap)
    {
        uint8_t i,j;
        uint8_t tempID;
    
        if(id == COMMAND_HANDLER_UPS_ADC_CAPTURE_ID)
        {
            tempID = COMMAND_HANDLER_PLOT_ADC_UPS_STRT_STP_PACKS_ID;
        }else
        {
            tempID = COMMAND_HANDLER_PLOT_ADC_DNS_STRT_STP_PACKS_ID;
        }
    
        // Generate packet ADC capture packets in START mode
        txPacket->length = COMMAND_HANDLER_PLOT_PACKET_SIZE;
        txPacket->payload[0] = COMMAND_HANDLER_USS_GUI_ID_BYTE;
        txPacket->payload[1] = tempID;
        txPacket->payload[2] = COMMAND_HANDLER_WRITE_CMD;
        txPacket->payload[3] = (uint8_t)COMMAND_HANDLER_PLOT_ADC_START_TX;
        txPacket->payload[4] = numOfPcks;
    
        CommandHandler_transmitPacket(txPacket);
    
        txPacket->length = COMMAND_HANDLER_CAPTURE_PACKET_SIZE;
        txPacket->payload[0] = COMMAND_HANDLER_USS_GUI_ID_BYTE;
        txPacket->payload[1] = id;
        txPacket->payload[2] = COMMAND_HANDLER_WRITE_CMD;
        txPacket->payload[4] = COMMAND_HANDLER_UPS_DNS_CAP_MAX_CAP_SIZE;
    
    
        // Transmit ADC UPS capture packets
        for(i = 1; i < numOfPcks ; i++)
        {
            txPacket->payload[3] = i;
    
            for( j = 0; j < (sizeof(uint16_t)*COMMAND_HANDLER_UPS_DNS_CAP_MAX_CAP_SIZE); j+=2)
            {
                txPacket->payload[(j + 5)] = *(pCap++);
                txPacket->payload[(j + 6)] = *(pCap++);
            }
    
            CommandHandler_transmitPacket(txPacket);
        }
    
        // Transmit final packet with remaining capture samples
        if(finalPckLength > 0)
        {
            txPacket->payload[3] = numOfPcks;
            txPacket->payload[4] = finalPckLength;
            i=0;
            while(finalPckLength > 0)
            {
                txPacket->payload[(i + 5)] = *(pCap++);
                txPacket->payload[(i + 6)] = *(pCap++);
                i+=2;
                finalPckLength--;
            }
    
            CommandHandler_transmitPacket(txPacket);
        }
    
        // Generate packet ADC capture packets in START mode
        txPacket->length = COMMAND_HANDLER_PLOT_PACKET_SIZE;
        txPacket->payload[0] = COMMAND_HANDLER_USS_GUI_ID_BYTE;
        txPacket->payload[1] = tempID;
        txPacket->payload[2] = COMMAND_HANDLER_WRITE_CMD;
        txPacket->payload[3] = (uint8_t)COMMAND_HANDLER_PLOT_ADC_STOP_TX;
        txPacket->payload[4] = numOfPcks;
    
        CommandHandler_transmitPacket(txPacket);
    
    
    }
    
    void CommandHandler_transmitPacket(Packet_t *packet)
    {
        Comm_writePacket(packet);
    
        while(g_ui16UARTTransmitBytesLeft!=0);
    
    }
    
    void Comm_writePacket(const Packet_t *packet)
    {
        //
        // Simply call the write buffer function, passing the packet parameters.
        //
        Comm_writeBuffer(packet->payload, packet->length);
    }
    
    void Comm_writeBuffer(const uint8_t *sourceBuffer, uint16_t sourceLength)
    {
    
        //
        // Because UART is being used, convert the source buffer into stream format.
        // This adds headers, byte stuffing, and the checksum.
        //
        sourceLength = Packet_convertToStream(
                &Comm_transmitBuffer[0],
                sourceBuffer,
                sourceLength
            );
        //
        // Transmit the packet via the UART interface.
        //
        UART_transmitBuffer(&Comm_transmitBuffer[0], sourceLength);
    
    }
    
    
    
    
    
    

    Is there anything I am doing wrong?

    Thanks in advance.



  • Hi Dylan, 

    Thanks for the reply, I am sending UPS and DNS capture along with the DToF values. When the MSP receives a UART command it goes to sending capture data mode as I have mentioned above.

    Thanks

  • I see okay. Is there a reason that you aren't just using the water demo example and cutting out some of the additional GUI functionality that you don't need? I believe the primary difference between the water demo and the template example is that one uses the GUI, while the other uses the simple UART interface. Could you just connect your UART pins to the logic analyzer instead of to the debugger and view the information that way?

    It may also help me to know what your end goal is for getting this data in this manner. Thanks for the explanation so far.

  • Hi Dylan, I don't have a logic analyzer but I tried to read the signal using a scope and I got the following result.

    I am trying to get this ups and dns data to plot the ADC graph just like USS GUI and I want to implement this in FR6047_USSSWLib_template_example.

  • This is running at about a 1 us bit time, or about 1 MBaud. Is that what you have the PC set for?

  • Yes, I have tried baud rate 1 M still I am getting gibberish. 

  • How can I change the baud rate to 4800 while transmitting this capture details?

  • Look at the comments in your code, it has numbers for 9600, which is what it should be sending, but the location in the user guide that tells you how.

    9600 baud should have 104 us bit times, so your timing is way off somewhere.

  • Hi Keith,

    I am able to get DToF and other results at a baud rate 4800 and If I send data to MSP at 4800 it is reading, however in the case UPS and DNS capture I am having issue.

  • Are you also sending the DTOF and other results using the same functions that you are sending the captures with? It sounds like the captures are still being sent with the settings for communication with the GUI, and the other results are being sent with the configuration that you want to use. If you continue to use the same functions that are used in the demo to communicate with the GUI in your PC, and you haven't changed them much, then it would make sense that the data being sent is not in the configuration that you want. If this is the case, then you would either need to rewrite more of the underlying code, or you would need to manually send the capture data using the same method that you are sending the DTOF and other results.

**Attention** This is a public forum