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 PaSi,

    PaSi said:
    I am not calling the function get_char_bit1()  every 50 micro seconds. 

    Thank you for clarifying - I did not think so, but your phrasing left some ambiguity and I thought it best to check rather than assume. 

    PaSi said:
    I had a question here do we need a differen timer timeout for sd_temp_get() and get_char_bit() or it can be implemented in same timer timeout handler.

    That is a good question - you should always make sure to keep interrupt handlers as short as possible, since they interrupt the regular program flow. In this case, the call to sd_temp_get is blocking, and it might block for as long as 50 µs each time it is called - which means a lot of time could be wasted here if you end up waiting for it each call.
    How often do you intend to get these temperature measurements?
    Could you possibly make these calls in your main context instead, which updates a kept variable, and then have the timeout handler do whatever it is you intend to do with the temperature data when it times out, for example? This would greatly reduce the time spent waiting for the sd_temp_get function to return. 

    PaSi said:
    here the app_tmers_start() is called after advertising_start in solution folder .

    Yes, it seemed to me that you were starting your timers before having finished the configuration, my mistake.

    PaSi said:
    as soon as i call get_char_bit function in timer timeout handler nRF connect App doesnt show nordic blinky.

    Are you getting the SOFTDEVICE_NOT_ENABLED error when you move the get_char_bit into the timer timeout handler?
    If not, what error message is printed when you move it into the timeout handler, and attempt to start the program execution?

    Best regards,
    Karl

  • Hi Karl,

    After minutely observing the problem occuring i exactly know where the problem is. Let me first describe how i get the sensor value first.

    Interfaced sensor with TWI and the reading the register of TWI. I read from a register using the function below to get extracted bit.

    THE FUNCTION BELOW READS VALUE FROM A PARTICULAR REGISTER OF SENSOR.

    extern uint8_t register_read(uint8_t register_address, uint8_t * destination, uint8_t number_of_bytes)
    {
     ret_code_t err_code;
     //Set the flag to false to show the receiving is not yet completed
     m_xfer_done = false;

     // Send the Register address where we want to read the data from
     err_code = nrf_drv_twi_tx(&m_twi, REG_ADDR, &register_address, 1, true);


       if (NRF_SUCCESS == err_code)
       {
       NRF_LOG_INFO("Success in tx_read");
       NRF_LOG_FLUSH();

        }

         m_xfer_done = false;

        err_code = nrf_drv_twi_rx(&m_twi, BQ21061_ADDR, destination, number_of_bytes);

       if (NRF_SUCCESS == err_code)
       {
       NRF_LOG_INFO("Success in rx");
       NRF_LOG_FLUSH();
        return destination;

         }


    }

    THIS FUNCTION EXTRACTS THE REQUIRED CHARGING BIT:

    extern ret_code_t charging_check(uint8_t*charge_bit)
    {
      uint8_t receive_buffer;
       uint8_t charging_bit;
      uint8_t charging_done_bit;
      register_read(REG_ADDR, &receive_buffer, 1);
      NRF_LOG_INFO("receive_buffer is %x", receive_buffer);
      NRF_LOG_FLUSH();
       if ((receive_buffer==65) || (receive_buffer==1)) 
      { 
       NRF_LOG_INFO("Charging");
       NRF_LOG_FLUSH();
       charging = 1;
       charging_done = 90;
       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 = 91;
       NRF_LOG_INFO("Charging completed %d", charging_done);
        NRF_LOG_FLUSH();
        }
      *charge_bit= charging_done;
    }

    void ble_modules_init(void)
    {

    leds_init();
    timers_init();

    // buttons_init();
    power_management_init();
    ble_stack_init();
    pwm_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    NRF_LOG_INFO("Blinky example started.");
    application_timers_start();
    advertising_start();
    // OneWireSlave_init();

    // Enter main loop.

    }

    I call ble_modules_init(void) in main after twi _nit()  (TWO WIRE INTERFACE FOR SENSOR)

    The message Blinky example started prints and after that

    success in tx_read function gets printed which means that the register read function doesnt get executed completely after called in timer_timeout_handler as it doesnt recieve anything. Could you suggest how do i go about this. Thanks for all the help .

    Kind Regards,

    PaSi

  • Hello PaSi,

    Thank you for your patience with this.

    PaSi said:
    THE FUNCTION BELOW READS VALUE FROM A PARTICULAR REGISTER OF SENSOR.
    Karl Ylvisaker said:
    Please use the "Insert->Code" option when sharing code here on DevZone.

    Please use the "Insert->Code" option when sharing code here on DevZone.

    PaSi said:
     // Send the Register address where we want to read the data from
     err_code = nrf_drv_twi_tx(&m_twi, REG_ADDR, &register_address, 1, true);


       if (NRF_SUCCESS == err_code)

    You are still not checking the returned error codes, like I asked in my initial reply.
    Please make sure that all returned error codes are passed to an APP_ERROR_CHECK.
    If you do not do this, you will have no way of knowing whether a function has failed and whether you need to do something about it or if your program can proceed as usual.
    Please do this, and confirm to me when it is done.

    PaSi said:

    The message Blinky example started prints and after that

    success in tx_read function gets printed which means that the register read function doesnt get executed completely after called in timer_timeout_handler as it doesnt recieve anything.

    What exactly does the log say? It is good that you include an explanation, but it is also beneficial if you can share the loggers output.

    PaSi said:
    Could you suggest how do i go about this.

    I suspect that the function has returned an error code. Please make sure that all returned error codes are passed to an APP_ERROR_CHECK.
    If you have defined DEBUG in your preprocessor defines, like I asked in my initial reply, you will have a detailed error message printed to your log whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.

    This is not relevant to the current issue, but I notice that your ble_modules_init seems to contain a "start execution" and "main loop" section. Is this intentional, or is the formatting of your code incorrect here?

    Looking forward to resolve this issue together.

    Best regards,
    Karl

Related