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

How to use lmt70 with nrf51

Hey everyone, I'm trying to use lmt70 with nrf51822. So, first of all, nrf51 has 10-bits ADC, the data sheet of lmt70 is recommended 12-bits of ADC.

I plugged the sensor, and read the value which is 801, I calculated the value of temperature in C and got 56 degC.

I guess it's a wrong value, cause I measure the temperature of room and I' m sure I have less than 56 degree.

my code is here

#define ADC_BUFFER_SIZE 10
static nrf_adc_value_t       adc_buffer[ADC_BUFFER_SIZE];
static nrf_drv_adc_channel_t channel1 = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_2);
    float LMT70_AMul = -0.0000000010642;
    float LMT70_BMul = -0.000005759725;
    float LMT70_CMul = -0.1789883;
    float LMT70_DMul = 204.857;
    
    /**
     * @brief ADC interrupt handler.
     */
    static void adc_event_handler(nrf_drv_adc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_ADC_EVT_DONE)
        {
            uint32_t i;
            float delta = 0;
            uint32_t count = p_event->data.done.size;
            for (i = 0; i < count; i++)
            {
                NRF_LOG_INFO("Current sample value: %d -> %d\r\n", i, p_event->data.done.p_buffer[i]);
                delta = p_event->data.done.p_buffer[i];
            }
            float LMT70_reading = ADC_RESULT_IN_MILLI_VOLTS(delta);
            //LMT70_reading *= 2.9;
            float A_val = LMT70_AMul * (LMT70_reading*LMT70_reading*LMT70_reading);
            float B_val = LMT70_BMul * (LMT70_reading*LMT70_reading);
            float C_val = LMT70_CMul * LMT70_reading;
    
            float degC = A_val+B_val+C_val+LMT70_DMul;
            //float tm = ((9/5)*degC)+32;
            NRF_LOG_INFO("My float number: %d\r\n", NRF_LOG_FLOAT(degC));
        }
    }
Related