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/EVM430-FR6047: Make UART work

Part Number: EVM430-FR6047

Tool/software: Code Composer Studio

Hello, 

I am trying to make UART work and later send total discharge data over it. I am unable to get any output. I have used the hal_uart module. I have changed the setting to use UART in place of I2C too. I have checked at both the UART modules present on the board. I have also initialized the uart module. Please guide me.

Regards,

Prudhvi Sagar

  • Hi Sagar,

    Please do not use the hal_uart module. It is designed for communicate with the USS GUI. You need to change some settings and it gonna be complicated. I suggest that you create a new project and add the UART function. Then you can debug your code more easier.

    Best regards,

    Cash Hao

  • Hello Cash,

    I have realized the same thing. Started using the example "USSSWLib_template_example" (edited it a bit) and I have implemented the UART communication. I am able to get values but looks like the precision is very low as TOF values are small numbers or it could be some issue with the code. Can  you confirm if the following code has everything initialized fine for Ultrasonic measurement and UART communication.

    #include <msp430.h>
    #include <stdint.h>
    #include <stdbool.h>
    #include "ussSwLib.h"
    #include "USS_Config/USS_userConfig.h"
    #include <stdio.h>
    #include <string.h>
    
    USS_Algorithms_Results algorithms_Results;
    
    void initUART();
    void initClock();
    void initGPIO();
    
    int main(void)
    {
        volatile USS_message_code code;
    
        initGPIO();
        initClock();
        initUART();
    
        code = USS_initAlgorithms(&gUssSWConfig);
        checkCode(code, USS_message_code_no_error);
    
        code = USS_configureUltrasonicMeasurement(&gUssSWConfig);
        checkCode(code, USS_message_code_no_error);
    
        code = USS_calibrateSignalGain(&gUssSWConfig);
        checkCode(code, USS_message_code_no_error);
    
        code = USS_estimateDCoffset(&gUssSWConfig,
            USS_dcOffEst_Calc_Mode_trigger_UPS_DNS_capture_controlled_by_ASQ);
        checkCode(code, USS_message_code_no_error);
    
        while (1)
        {
    
            //Check both captures.
            //code = USS_startLowPowerUltrasonicCapture(&gUssSWConfig);
            code = USS_startUltrasonicMeasurement(
                   &gUssSWConfig, USS_capture_power_mode_low_power_mode_0);
            checkCode(code, USS_message_code_no_error);
    
            code = USS_runAlgorithms(&gUssSWConfig, &algorithms_Results);
            checkCode(code, USS_message_code_no_error);
    
    
         		  //DelTOF - 8        algorithms_Results.deltaTOF
            //volumerate - 12    algorithms_Results.volumeFlowRate
                    //algorithms_Results.totalTOF_UPS
           
            char stringTemp[80];
            sprintf(stringTemp, "%f", algorithms_Results.volumeFlowRate);
    
            P7OUT ^= BIT6;             //Checking
           unsigned int len;
            len = strlen(stringTemp);
    
                    for(i=0; i<14; i++){
            while(!(UCA0IFG&UCTXIFG));
            UCA0TXBUF = stringTemp[i];
            }
    
    
            USS_generateLPMDelay(&gUssSWConfig,
                                 USS_low_power_mode_option_low_power_mode_3,
                                 32768);
    
        }
    
    }
    
    void checkCode(USS_message_code code, USS_message_code expectedCode)
    {
    
        if(code != expectedCode)
        {
            // Trap code
    
            while(1);
        }
    }
    
    
    void initGPIO()
    {
        // Configure GPIO
               P2SEL0 &= ~(BIT0 | BIT1);
               P2SEL1 |= BIT0 | BIT1;                  // USCI_A0 UART operation
               PJSEL0 |= BIT4 | BIT5;                  // For XT1
    
    }
    
    void initUART()
    {
    
        // Configure USCI_A0 for UART mode
           UCA0CTLW0 = UCSWRST;                    // Put eUSCI in reset
           UCA0CTLW0 |= UCSSEL__ACLK;              // CLK = ACLK
           UCA0BRW = 3;                            // 9600 baud
           UCA0MCTLW |= 0x5300;                    // 32768/9600 - INT(32768/9600)=0.41
                                                   // UCBRSx value = 0x53 (See UG)
           UCA0CTLW0 &= ~UCSWRST;                  // Initialize eUSCI
    
    }
    
    void initClock()
    {
    
        // XT1 Setup
            CSCTL0_H = CSKEY_H;                     // Unlock CS registers
            CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
            CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;   // Set all dividers
            CSCTL4 &= ~LFXTOFF;
            do
            {
                CSCTL5 &= ~LFXTOFFG;                // Clear XT1 fault flag
                SFRIFG1 &= ~OFIFG;
            } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
            CSCTL0_H = 0;                           // Lock CS registers
    }
    
    
    
    

  • Hi Sagar,
    It seems no big issue in your code. However, I suggest to debug each function at once.

    For the ultrasonic measurement part, use the original 'MSP430FR6047EVM_USS_Water_Demo' code comparing the TOF results with this present code. If you are getting some similar results, then it is not the ultrasonic issue.

    For the UART communication part, remove the ultrasonic settings in your present code. And just send out some words, you can check if the UART module works fine.

    Best regards,
    Cash Hao
  • Hello,

    I had already checked uart part by sending dummy float values. Upto a certain number of decimal places it is able to send fine. UPS, DNS and DelTOF are very low values hence I am unable to confirm the working of USS. I will be later sending only lps and total discharge so resolution is not a big issue for me.

    Is there anyway by multiplying these values with 10^6 to obtain better values.

    Regards,

    Prudhvi Sagar

  • Hi,
    You can use this API 'USS_getResultsInFloat()' to get the USS results in float. Then you can multiply and output as you want.

    Best regards,
    Cash Hao
  • Hello,

    Ty for the support. I am confused with the usage of 'USS_getResultsInFloat()'. It has 2 pointers. For the fixed point result should I link it to "USS_runAlgorithms(&gUssSWConfig, &algorithms_Results);"? Then I would get the results in floating point?

    Regards,

    Prudhvi Sagar

  • Hi Sagar,

    You can see a clear definition of this API in here.

      

    Best regards,

    Cash Hao

  • Hello,
    As i understand it converts fixed point results to floating point. Where do I get the fixed point results? Are they the results of "USS_runAlgorithms(&gUssSWConfig, &algorithms_Results);"?

    Regards,
    Prudhvi Sagar
  • Hi Sagar,
    It is this one 'USS_runAlgorithmsFixedPoint()'

    Best regards,
    Cash Hao
  • Hello,
    I am not getting consistent data compared to GUI and getting random erroneous values with the above code. So there must an issue with the way I am using USS. Can you help me approach this problem.

    Isnt USS_runAlgorithms(&gUssSWConfig, &algorithms_Results); also supposed to give results in float?

    Regards,
    Prudhvi Sagar
  • Hello,

    I have a couple of doubts in the code i posted before.

    1. The checkCode function works only if it has some trap code in it. Isnt it suppose to trap irrespective of the code in it.

    void checkCode(USS_message_code code, USS_message_code expectedCode)
    {
    
        if(code != expectedCode)
        {
            // Trap code
           // P7OUT ^= BIT6;
           // P8OUT ^= BIT0;
            while(1);
        }
    }


    2. Now as the checkCode is working fine the code gets stuck at

    //Some issue here // code = USS_calibrateSignalGain(&gUssSWConfig); // checkCode(code, USS_message_code_no_error);

     and if I comment the above part. It also gets stuck here.

            code = USS_runAlgorithms(&gUssSWConfig, &algorithms_Results);
            checkCode(code, USS_message_code_no_error)

    3. What is the difference in my code w.r.t GUI demo which is stopping my code to work. Do  I initialize clock, adc etc. similar to GUI to work or any other thing I am missing?

    Regards,

    Prudhvi Sagar

  • Hi Sagar,
    USS_runAlgorithms supposed to give fixed point result.
    checkCode function is meanly used for debugging, it help us to find the error function.
    I suggest you can try our demo code first and check all the functions. Then you can add extra function one by one to see where the errors come from.

    Best regards,
    Cash Hao

**Attention** This is a public forum