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.

LAUNCHXL-CC1310: Can I please get an example to take user input in hex format for UART

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

Hi All, 

I need a example for accepting user input in hex format. I need to add UUID to the boards which I am creating and need to accept the data from the user. it would be 4 bytes of data. Once the data is accepted I can use the NVS code to store the data in the address. 

Any examples elated to this would be helpful, I can use the data on CC1310 lauchpad for testing.

Thank you.

  • Are you using the UART to get the data from a terminal on the PC?
    Just what do you need help with? Parsing? Converting strings to integers?

    Can you get characters from the PC to the CC1310?
  • void set_absoluteFrequency(){
            int8_t i;
            uint16_t freq;
            uint16_t freq_2;
            uint64_t fractFreqHz;
    
            freq = 0;
                for(i = 0; i< 4; i++) {
                    freq = freq * 10 + (uart_s.arg[0][i]) - (char)CHAR_ZERO;
                }
                uuid = freq;
              freq_2 = 0;
                            for(i = 4; i< 7; i++) {
                                freq_2 = freq_2 * 10 + (uart_s.arg[0][i]) - (char)CHAR_ZERO;
                            }
                            uuid_2 = freq_2;
        /*  fractFreqHz = 0;
                    for(i = 4; i< 10; i++) {
                        fractFreqHz = fractFreqHz * 10 + (uart_s.arg[0][i] - (char)CHAR_ZERO);
                    }
    
                    // Convert frequency in Hz to format that the radio understands while retaining precision
                    RF_cmdFs.__dummy2 = (fractFreqHz * 4295); //>> 16;  */
            // Close previous connection to radio
          //  RF_close(rfHandle);
            freqToString();
        rfHandle = NULL;
    }
    
    

    Thank you for Keith for the quick response. I have the above code accepting data in some format. But I want it to accept hex format too.
    I trying to modify this code to accept 4 bytes of hex or some other way to accept hex data and store it in a variable.
    I am getting the input from coolterm / uart interface on PC.
  • This code converts decimal numbers. You need to rewrite it to convert uart_s.arg[0][i] from hex characters to integers.

    How do you know whether you are getting hex or decimal? If you use the "\x" tag, you will have to strip it out when you receive it and set a flag to indicate that uart_s.arg[0][i] is hex.

    I would make the "10" a variable that is either 10 or 16 based on the hex flag and replace "(uart_s.arg[0][i]) - (char)CHAR_ZERO" with a function that returns a number that interprets uart_s.arg[0][i] based on the state of the hex flag.
  • Thank you Keith for your input. I think I understand what you meant. let me try implementing it and see if it works. Will keep you posted.
  • Thank you for your response the issue was solved.