This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Hello all i want to interface temperature sensor with nRF52 DK. And send the temperature values to the users smart phone. I have checked with the tutorial and have used the sd_temp_get() function to get the temperature using the on board sensor.

 nd Since i am still a newbie to nordic i wanted to know how can i break the task in smaller steps. 

1)As a first step i get the values in temperature form using saadc. 

2)How can i notify the value just as it does after calling for sd_temp_get().

3)As a 3rd question I have already interfaced the battery management IC with nrF52 and extracted the required bit. I wish to send that bit and read/notify it on one of the characteristics. But the value doesnt get updated.

Any inputs would be helpful 

  • Hello,

    From your description it seems to me that you have successfully acquired the sensor value, and now just seek to send it to a connected smartphone, could you confirm that this is correct?

    How can i notify the value just as it does after calling for sd_temp_get().

    Which example are you working out of? To send the value to a connected device you can use a notification.

    You mention in your title (which you should keep to a descriptive minimum, not a body of text, by the way) that you have checked with "the tutorial", which tutorial are you referring to here?
    To learn more about how you can setup your own custom service, and configure it to notify its peer if the value changes, I highly recommend taking a look at the Beginners Service tutorial

    As a 3rd question I have already interfaced the battery management IC with nrF52 and extracted the required bit. I wish to send that bit and read/notify it on one of the characteristics. But the value doesnt get updated.

    How are you attempting to do this now, and what do you observe when you attempt this? Is there an error code generated, or does the device reset? Does the call to send the notification return successfully?
    It would be great if you could share some code here, and explain what you attempted, what you expected it to do, and how it failed.
    The more detail you provide, the easier it will be for us to resolve this issue together!
    Please use the "Insert->Code" option when sharing code here on DevZone.

    Best regards,
    Karl 

  • Hello Karl Thanks for replying .

     I would like to start with 3rd question first. 

    The Battery management IC has been connected using TWI.  

    I have mentioned how i have extracted the charging bit and how have i implemented the BLE part. I have followed the exact steps provided in tutorial for Ble custom characteristics and i can see the value of temperature on nRF connect  APP. The problem that i am facing is if i use the get_charging_bit_1(&charging_bit) in timer timeout handler the program compiles properly but the device(nordic blinky) doesnt appear on the nRFconnect App. If i comment get_charging_bit_1 out from timer timeout handler i can see the device and all my characteristics on nRFconnect App.  

    uint8_t charging_check(void)
     {
      uint8_t receive_buffer;
      uint8_t charging;
      uint8_t charging_done;
      b_register_read(BQ_SAT_0_REG_ADDR, &receive_buffer, 1);
      NRF_LOG_INFO("receive_buffer is %x", receive_buffer);
      NRF_LOG_FLUSH();
      if ((receive_buffer==65) || (receive_buffer==1))         // 65 is decimal equivalent of 41 in hex 
      {
       NRF_LOG_INFO("Charging");
       NRF_LOG_FLUSH();
       charging = 1;
       charging_done = 0;
       
       NRF_LOG_INFO("Battery is charging, charging = %d", charging);
       NRF_LOG_FLUSH();
      
      }
      else if (receive_buffer==33)                             //33 is decimal equivalent of 21 in hex
      {
       NRF_LOG_INFO("Charged");
       NRF_LOG_FLUSH();
       charging_done = 1;
      
       NRF_LOG_INFO("Charging completed %d", charging_done);
       NRF_LOG_FLUSH();
      }
      return charging_done;
     }
    
    extern int8_t get_charging_bit_1(int*charging_bit)
    { 
     {int temp;
     temp=charging_check();
     *charging_bit=temp;
     }
     
    }
    
    
    
    void charging_characteristic_update(ble_cus_t *p_cus, int32_t *charging_bit)
    {
        // OUR_JOB: Step 3.E, Update characteristic value
        if (p_cus->conn_handle != BLE_CONN_HANDLE_INVALID)
      {
          uint16_t               len = 4;
          ble_gatts_hvx_params_t hvx_params;
          memset(&hvx_params, 0, sizeof(hvx_params));
    
          hvx_params.handle = p_cus->custom_value_handles_2.value_handle;
          hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
          hvx_params.offset = 0;
          hvx_params.p_len  = &len;
          hvx_params.p_data = (uint8_t*)charging_bit;  
    
          sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
    
    
    
      }
    
     
     
     static void timer_timeout_handler(void * p_context)
    {
     
       int8_t charging_bit = 0;
       static int8_t previous_charging_bit=0;
       get_charging_bit_1(&charging_bit);
       if(charging_bit != previous_charging_bit)
                       {
                           
                           charging_characteristic_update(&m_cus, &charging_bit);
                       }
    }
     

  • PaSi said:
    Thanks for replying .

    No problem at all, I am happy to help!

    PaSi said:
    I have followed the exact steps provided in tutorial for Ble custom characteristics and i can see the value of temperature on nRF connect  APP.

    Thank you for clarifying, this is very helpful information - so we know the issue is not with the BLE communication itself, great!

    PaSi said:
    The problem that i am facing is if i use the get_charging_bit_1(&charging_bit) in timer timeout handler the program compiles properly but the device(nordic blinky) doesnt appear on the nRFconnect App. If i comment get_charging_bit_1 out from timer timeout handler i can see the device and all my characteristics on nRFconnect App.  

    This sounds to me like your device is failing within some of the function calls here. Does the device reset when this happens, or does everything seem to function as normal - except that you can not find it in the nRF Connect application?

    It is hard to get the complete picture from the provided code snippet, but I notice that you do not check the error code returned by sd_ble_gatts_hvx. If you do not check the error codes returned by SDK functions, you will have no way of knowing if the function call was successful or not. You should therefore always pass the returned error codes to an APP_ERROR_CHECK.  Please go through your code, and make sure that all returned error codes are checked.
    Furthermore, please make sure that DEBUG is defined in your preprocessor defines, like shown in the included image.

    This will make your logger print a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.

    Please do this, and let me know if your logger outputs any such error message. If you do not get any such message, we will have to take a closer look at all the functions called as part of your timer handler, to find out which function / function call that is the reason for this behavior.

    Best regards,
    Karl

    P.s on a code-quality note I would highly recommend that you do not use magic numbers in your code, but rather create proper defines for these addresses and/or return codes that you use. This will both increase your codes readability and maintainability, and will save you for a lot of work and frustration in the long run.

  • Hi Karl,

    the problem lies when i call the get_char_bit1 () function in the timer_timeout_handler if i remove in this case the nordic blinky device doesnt show on nrf Connect app.

    As sd_temp_get() sends temp values every 0.5micro seconds how can i implement a similar functionality to get the get_char_bit1() every 0.5micro seconds. Could that be a solution. 

    I will debug again and write a reply to you. You have been a great help.

  • PaSi said:
    the problem lies when i call the get_char_bit1 () function in the timer_timeout_handler if i remove in this case the nordic blinky device doesnt show on nrf Connect app.

    Yes, I too suspect that one of the functions called as part of your call to get_char_bit1 is the culprit here.

    PaSi said:
    As sd_temp_get() sends temp values every 0.5micro seconds how can i implement a similar functionality to get the get_char_bit1() every 0.5micro seconds. Could that be a solution. 

    Are you referring to the 50 µs it takes for sd_temp_get to return? This does not mean that you have to call the function every 50 µs, it means that approximately 50 µs will pass from you call the function till the program continues. The function is blocking, so it will not let the program proceed while the reading takes place.
    You do not need to call this on an interval, you can call it whenever you want to check the temperature.

    PaSi said:
    I will debug again and write a reply to you. You have been a great help.

    I am happy to hear that, thank you! It is no problem at all.

    Great, I look forward to hearing what you find in your debugging!

    Best regards,
    Karl

Related