Issues with Floating-Point Arithmetic in nRF52832 Project using Segger Embedded Studio

Recently, we started developing our new project using the nRF52832 as our controller.

We are using Segger Embedded Studio (5.42a) as our IDE.

My question is: Are there any issues while using float variable arithmetic operations in Segger Embedded Studio? Are there any additional changes needed to make in the IDE while using float variables?

Our project involves reading advertising packets from nearby temperature sensor beacons, extracting the temperature from these packets, and printing it to the log console. When we take the bits for temperature and humidity, convert them, and then calculate the actual temperature and humidity using float variables, we are getting junk values or unexpected results.

SDK: nRF5 SDK 17.0.2

IDE: Segger Embedded Studio 5.42a

Controller: nRF52832

Parents Reply Children
  •  ,

    iam used printf instead of "NRF_LOG" .

    i will attach the code for better understanding .  

     case BLE_GAP_EVT_ADV_REPORT:
           
              {
                // Extract advertising report data
                ble_gap_evt_adv_report_t const * p_adv_report = &p_gap_evt->params.adv_report;
    
                // Define the target MAC address
               // uint8_t target_mac[6] = {0xF4, 0x12, 0xFA, 0xE6, 0x4F, 0x0E};
    
               //if (memcmp(p_adv_report->peer_addr.addr, target_mac, sizeof(target_mac)) == 0)
        
                // Log the advertising device's address
                 if ((p_adv_report->peer_addr.addr[5] == 0xBC) && (p_adv_report->peer_addr.addr[4] == 0x57)&&(p_adv_report->peer_addr.addr[3] == 0x29)&&(p_adv_report->peer_addr.addr[2] == 0x00)&&(p_adv_report->peer_addr.addr[1] == 0x93)&&(p_adv_report->peer_addr.addr[0] == 0xDA))
             {
                NRF_LOG_INFO("Device Address: %02X:%02X:%02X:%02X:%02X:%02X",
                             p_adv_report->peer_addr.addr[5],
                             p_adv_report->peer_addr.addr[4],
                             p_adv_report->peer_addr.addr[3],
                             p_adv_report->peer_addr.addr[2],
                             p_adv_report->peer_addr.addr[1],
                             p_adv_report->peer_addr.addr[0]);
                printf("Device Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
                       p_adv_report->peer_addr.addr[5],
                       p_adv_report->peer_addr.addr[4],
                       p_adv_report->peer_addr.addr[3],
                       p_adv_report->peer_addr.addr[2],
                       p_adv_report->peer_addr.addr[1],
                       p_adv_report->peer_addr.addr[0]);
    
                //// Log the advertising data
                //NRF_LOG_INFO("Advertising Data (Length: %d):", p_adv_report->data.len);
              
                NRF_LOG_HEXDUMP_INFO(p_adv_report->data.p_data, p_adv_report->data.len);
                printf("\nAdvertising Data (Length: %d): ", p_adv_report->data.len);
                for (uint32_t i = 0; i < p_adv_report->data.len; i++)
                {
                   printf("%02X ", p_adv_report->data.p_data[i]);
                }
                printf("\n");
                //temp_humidity((char *)p_adv_report->data.p_data);
                char ch_humidity[8];
                char temperature[8];
                printf("17th pos: %02X ", p_adv_report->data.p_data[17]);
                printf("18th pos: %02X ", p_adv_report->data.p_data[18]);
                int temp = (int)p_adv_report->data.p_data[17]+ (int)(p_adv_report->data.p_data[16]<< 8);
                printf("temp : %d\t",temp);
                int calcTempScaled = (temp * 100) / 256;
                printf("calcTemp (scaled): %d.%02d\n", calcTempScaled / 100, calcTempScaled % 100);
                float calcTemp = (float)temp / 256.0f;
                printf("calcTemp: %.2f\n", calcTemp);
                //sprintf(temperature," %d.%02d", calcTempScaled / 100, calcTempScaled % 100);
                //int hum = (int)p_adv_report->data.p_data[19] + (int)(p_adv_report->data.p_data[18]<< 8);
                float calcHum = (hum / 256.0f);
                sprintf(ch_humidity,"%6.1f", calcHum);
               //int calcHumScaled = (hum * 100) / 256; // Scale result to represent two decimal places
               // Format humidity as a string
               //sprintf(ch_humidity, "%d.%02d", calcHumScaled / 100, calcHumScaled % 100);
    
               // printf("Temperature: %s °C\t humidity : %s\n", temperature,ch_humidity);
                nrf_delay_ms(100);
              }
            }
            break;

    is there any need of enabling "FPU" in seggar embedded studio . if it is needed how can i enable it ? . 

  • siltvm,

    No, you don't need to do anything special to enable FPU. It should be enabled by default. 
    Regardless, its role is not to enable, but only to speed up floating point arithmetic. Even with FPU disabled, you should still have floating point arithmetic support.

    The issue is still likely in printing support. You can enable it in Project Option, following this DevZone post:  Float value not getting printed

Related