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.

Compiler/LAUNCHXL-CC2650: Value seen in hex

Part Number: LAUNCHXL-CC2650

Tool/software: TI C/C++ Compiler

Hello,

I am trying to send an integer value, but I can only see the hex value. How to convert or present a char value in decimal?

thanks,

Rathna

  • Rathna said:
    but I can only see the hex value.

    Exactly how do you see it?  What makes you think it is a hex value?

    Thanks and regards,

    -George

  • I don't see any data in the value attribute, I only see a hex value.
    I want to sent voltage in milli volts, so can you help me with the length of the value?

    thanks,
    Rathna
  • Whatever you are seeing is just interpreting a sequence of bits. It might display in hex, but it could equally be displayed in binary, octal, decimal or hex. The underlying data can still be used for any calculations.

    As asked, where are you seeing this data? Can you provide a screenshot?

    If you getting data via serial, you may need to use sprintf() or something similar to send ASCII characters instead.
  • Hello,

    Thank you for the response. I am using Ble Scanner App, I am working on SimpleBLEPeripheral Example.

    This is my code in simpleProfile_ReadAttr(), and I am using Char4 to display data:

     case SIMPLEPROFILE_CHAR4_UUID:
          {
              uint8_t level;
    
              level = battMeasure();
              battLevel = level;
              if (level < battLevel)
              {
                  // Update level
                 battLevel = (uint8)(level & 0x00FF);
              }
    
              *pLen = 1;
              pValue[0] = battLevel;
    
           }

    And here is how I am getting Voltage value,

    static uint8_t battMeasure(void)
    {
      uint32_t batt;
    
      // Read the battery voltage (V), only the first 12 bits
      batt = AONBatMonBatteryVoltageGet();
    
    
      batt = (batt * 125) >> 5;
    
      return batt;
    }

    I am getting, 0x78 as the hex value, and x as the value.

    Can you please guide me through this.

    Thanks,

    Rathna

  • 0x78 is 120.

    Again, where are you seeing 0x78? No wonder you get 'x', since that is the character you get with decimal 120, or 0x78.

    You probably need to use sprintf() to change 0x78 to "120" and send those three characters.
  • Hi Rathna,

    You send the battery value in hex format using Bluetooth Service Characteristic, which is normal. You then translate this at the app side, for example in decimal value.

    If you use IOS LightBlue App, there is an option to change the value format.

    -kel
  • Hi,

    You copied that code from battservice.c. At battservice.c battMeasure() returns percentage 0-100 so uint8_t is enough.

    static uint8_t battMeasure(void)
    {
    uint32_t percent;

    // Call measurement setup callback
    if (battServiceSetupCB != NULL)
    {
    battServiceSetupCB();
    }

    // Read the battery voltage (V), only the first 12 bits
    percent = AONBatMonBatteryVoltageGet();

    // Convert to from V to mV to avoid fractions.
    // Fractional part is in the lower 8 bits thus converting is done as follows:
    // (1/256)/(1/1000) = 1000/256 = 125/32
    // This is done most effectively by multiplying by 125 and then shifting
    // 5 bits to the right.
    percent = (percent * 125) >> 5;
    // Convert to percentage of maximum voltage.
    percent = ((percent* 100) / battMaxLevel);

    // Call measurement teardown callback
    if (battServiceTeardownCB != NULL)
    {
    battServiceTeardownCB();
    }

    return percent;
    }

    -kel
  • So If I use uint32_t for measuring the voltage, how do I display it?
    Can you give me an example?

    Regards,
    Rathna
  • Hi Rathna,

    You can just remove the changing to percentage, then return the 4 byte battery data.

    static uint32_t battMeasure(void)
    {
    uint32_t battVoltage;

    // Read the battery voltage (V), only the first 12 bits
    battVoltage = AONBatMonBatteryVoltageGet();

    // Convert to from V to mV to avoid fractions.
    // Fractional part is in the lower 8 bits thus converting is done as follows:
    // (1/256)/(1/1000) = 1000/256 = 125/32
    // This is done most effectively by multiplying by 125 and then shifting
    // 5 bits to the right.
    battVoltage = (battVoltage * 125) >> 5;

    return battVoltage;
    }

    -kel