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

I2C implementation between nrf52832 and cypress capsense button CY8CMBR2110-24LQ.

Hello!!

I want to implement I2C between nrf52832 and capsense button (CY8CMBR2110-24LQ) and want to put it to sleep mode so that I could get ~2-3uA  if there is no activity. Previously, I was using bsp_evt_handler() but wasn't able to achieve low power mode on nrf52832. The capsense is going to be pull up ( default ). 

I would appreciate any soon response. 

1. Capsense I2C lines are connected to  nrf52832 I2C lines.

2. 10 Capsense Buttons are pull up.

3. One Bi-color LED will be there.

4. Need to put in sleep mode for inactivity. 

Thanks

Parents
  • So what are you observing? Where did it fail? 1: Does it work? 2: Is the current consumption too high?

    1: If not, what happens?

    2: If so, have you tried measureing the current consumption if you don't enable the button/bsp? Does that give the current consumption you expect? Is the I2C enabled? Is it disabled again?

    BR,

    Edvin

  • Hi 

    So what are you observing? Where did it fail?

    My code isn't working for low power mode after adding cypress capsense (CY8CMBR2110-24LQ). It fails when it needs to go to System OFF. 1: No 2: Yes ~1.2mA.

    1: If you could suggest me any example how to implement I2C and then putting capsense on sleep mode for inactivity.

    2. Yes, Nothing changes on current consumption ( ~1.2mA ) for disabling button button/bsp. 

    Does that give the current consumption you expect?

    No

    Is the I2C enabled?

    I am not using I2C. I have just use bsp_evt_handler.

    Thanks

  • Hi !!

    Before implementing to I2C to my final code, I am trying to implement deep sleep state of my cypress capsense (CY8CMBR2110-24LQ) with host control (nrf52832), so I'm using TWI_SENSOR example as a reference to implement. But I am not able to write and read register properly. I am attaching my main.c below : 

    /**
     * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     * @defgroup tw_scanner main.c
     * @{
     * @ingroup nrf_twi_example
     * @brief TWI Sensor Example main file.
     *
     * This file contains the source code for a sample application using TWI.
     *
     */
    
    #include <stdio.h>
    #include "boards.h"
    #include "app_util_platform.h"
    #include "app_error.h"
    #include "nrf_drv_twi.h"
    #include "nrf_delay.h"
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    /** slave address **/
    #define DEFAULT_SLAVE_ADDRESS 0x37
    
    /** capsense i2c pins **/
    #define CAPSENSE_SCL_PIN  27
    #define CAPSENSE_SDA_PIN  26
    
    
    #define DEFAULT_SLAVE_ADDRESS	0x37	/* Factory default slave I2C address for initialization */
    
    /* TWI instance ID. */
    #define TWI_INSTANCE_ID     0
    
    /** deep sleep mode register **/
    #define REG_ADDR                 0x00
    #define IN_DEEP_SLP_VALUE        0x10
    #define OUT_DEEP_SLEEP_VALUE     0x00
    
    /* Indicates if operation on TWI has ended. */
    static volatile bool m_xfer_done = false;
    
    /* TWI instance. */
    static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
    
    uint8_t register_address[2] = {REG_ADDR, IN_DEEP_SLP_VALUE};    //Address of the register to be read
        
    /**
     * @brief TWI initialization.
     */
    void twi_init (void)
    {
        ret_code_t err_code;    
        const nrf_drv_twi_config_t twi_config = {
           .scl                = CAPSENSE_SCL_PIN,
           .sda                = CAPSENSE_SDA_PIN,
           .frequency          = NRF_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }
        
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        ret_code_t err_code;
        uint8_t sample_data;
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
        twi_init();
        
        /** writing value to register **/
        err_code = nrf_drv_twi_tx(&m_twi, DEFAULT_SLAVE_ADDRESS, register_address, sizeof(register_address), false);
        if(err_code == NRF_SUCCESS)
          {
    	printf("register value is set");
          }
        //APP_ERROR_CHECK(err_code);
        NRF_LOG_FLUSH();
        nrf_delay_ms(5);
    
        /** reading register value **/
        uint8_t register_address[2] = {REG_ADDR, IN_DEEP_SLP_VALUE};
        err_code = nrf_drv_twi_tx(&m_twi, DEFAULT_SLAVE_ADDRESS, register_address, 1, false);
        if(err_code == NRF_SUCCESS)
          {
    	printf("register value is set");
          }
          NRF_LOG_FLUSH();
                    
          nrf_delay_ms(60);
          err_code = nrf_drv_twi_rx(&m_twi, DEFAULT_SLAVE_ADDRESS, &sample_data, sizeof(sample_data));
        
        if (err_code == NRF_SUCCESS)
          {
            //printf("Written register value = 0x%x", sample_data);
          }		
          NRF_LOG_FLUSH();
    
        while (true)
        {
            printf("Written register value = 0x%x\n\r", sample_data);
            nrf_delay_ms(1000);
        }
    }
    
    /** @} */

    Thanks

  • Edvin said:
    So try to compare your application before and after you added the capsense buttons. Is your I2C active? Does the current behave like you expect if you never enable I2C? Do you disable the I2C before you go to system off?

     

    Edvin said:
    techietech said:
    No, application doesn't reset and also enter system off.

     what does that mean? Does the device enter system off or not?

     You didn't answer any of my previous questions. And now it doesn't answer the TWI calls either? Have you checked the datadsheet for the buttons you are using? Or do you have any drivers? Note that you are not sending the IN_DEEP_SLEEP_VALUE in that call:

        err_code = nrf_drv_twi_tx(&m_twi, DEFAULT_SLAVE_ADDRESS, register_address, 1, false);

    Because the length is set to one. You are only sending the first byte.

  • Hi !!

    So try to compare your application before and after you added the capsense buttons. Is your I2C active? Does the current behave like you expect if you never enable I2C? Do you disable the I2C before you go to system off?

    I compared my application before and after capsense i.e. I found that my system goes to System OFF . But When I attached capsense button I am not getting SYSTEM OFF Condition. No, I am not using I2C but it is connected with pin GPIO 26 & 27. No current doesn't behave like as expected. I also tried to disable the I2c using the api I have found on community but there is no luck.

    Have you checked the datadsheet for the buttons you are using? Or do you have any drivers? Note that you are not sending the IN_DEEP_SLEEP_VALUE in that call

    Yes I have checked the datasheet and found the address 0x00 and was trying to write Ox10 but not able to do that.

    err_code = nrf_drv_twi_tx(&m_twi, DEFAULT_SLAVE_ADDRESS, register_address, 1, false);

    I tried with 2 bytes also. 

    Could you please help me out with writing and reading using I2C. My slave address is 0x37. I want to read register at 0x00 and then want to write 0x10 and then after I want to read written value?

    Eventually, after getting deep sleep mode in I could implement it to capsense button (CY8CMBR2110-24LQ). 

    I will appreciate your soon response.

    Thanks 

  • You need to ask the sensor producers what commands to use to read and write to the values that you are trying to acheive. 

     

    techietech said:
    No, I am not using I2C but it is connected with pin GPIO 26 & 27.

     Based on the TWI call it looks like you are using I2C (TWI and I2C is the same).

  • Hi !!

    You need to ask the sensor producers what commands to use to read and write to the values that you are trying to acheive

    I got this and was able to use read and write function properly. I was getting ~1.2uA when I used only initializing twi_init(); nrf_drv_twi_tx(); & nrf_drv_twi_rx(); 

    After adding this to my original code in modified ble_app_beacon example, the current consumption increased to ~1.2mA. I also tried with disabling other functions such as ble stack, advertising and the current consumption gets lower to ~400uA. After debugging I found that nrf52832 chip isn't going to sleep mode. 

    I am attaching my main.c below so that you could suggest why nrf52832 chip is not going to sleep mode.

    /**
     * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     *
     * @defgroup ble_sdk_app_beacon_main main.c
     * @{
     * @ingroup ble_sdk_app_beacon
     * @brief Beacon Transmitter Sample Application main file.
     *
     * This file contains the source code for an Beacon transmitter sample application.
     */
    
    /******** Ble_beacon_remote **********/
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "nordic_common.h"
    #include "bsp.h"
    #include "nrf_soc.h"
    #include "nrf_sdh.h"
    #include "nrf_sdh_ble.h"
    #include "ble_advdata.h"
    #include "app_timer.h"
    #include "nrf_pwr_mgmt.h"
    #include "nrf_drv_clock.h"
    #include "nrf_drv_saadc.h"
    #include "nrf_drv_ppi.h"
    #include "nrf_drv_timer.h"
    #include "boards.h"
    #include "nrf.h"
    #include "nrf_delay.h"
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #define DEVICE_NAME                     "DeviceName"
    #define APP_BLE_CONN_CFG_TAG            1                                  /**< A tag identifying the SoftDevice BLE configuration. */
    
    #define BATTERY_LEVEL_MEAS_INTERVAL     APP_TIMER_TICKS(5000)              /**< Battery level measurement interval (ticks). */
    
    #define NON_CONNECTABLE_ADV_INTERVAL    MSEC_TO_UNITS(400, UNIT_0_625_MS)  /**< The advertising interval for non-connectable advertisement (100 ms). This value can vary between 100ms to 10.24s). */
    
    #define APP_BEACON_INFO_LENGTH          0x17                               /**< Total length of information advertised by the Beacon. */
    #define APP_ADV_DATA_LENGTH             0x15                               /**< Length of manufacturer specific data in the advertisement. */
    #define APP_DEVICE_TYPE                 0x02                               /**< 0x02 refers to Beacon. */
    #define APP_COMPANY_IDENTIFIER          0x0059  
    
    
    #define ADC_REF_VOLTAGE_IN_MILLIVOLTS   600                               /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
    #define ADC_PRE_SCALING_COMPENSATION    6                                 /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
    #define DIODE_FWD_VOLT_DROP_MILLIVOLTS  270                               /**< Typical forward voltage drop of the diode . */
    #define ADC_RES_10BIT                   1024                              /**< Maximum digital value for 10-bit ADC conversion. */
    
    volatile uint16_t remote_led_indication;
    //static uint8_t      packet_buf;          /****** TX buffer for buttons ******/
    static uint8_t      packet_buf[2];          /****** TX buffer for buttons ******/
    
    /**@brief Macro to convert the result of ADC conversion in millivolts.
     *
     * @param[in]  ADC_VALUE   ADC result.
     *
     * @retval     Result converted to millivolts.
     */
    #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
            ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / ADC_RES_10BIT) * ADC_PRE_SCALING_COMPENSATION)
    
    #define DEAD_BEEF                       0xDEADBEEF                         /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
    #define HIGH        1
    #define LOW         0
    
    static ble_gap_adv_params_t m_adv_params;                                  /**< Parameters to be passed to the stack when starting advertising. */
    static uint8_t              m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; /**< Advertising handle used to identify an advertising set. */
    static uint8_t              m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];  /**< Buffer for storing an encoded advertising set. */
    
    static nrf_saadc_value_t m_adc_buf;
    
    APP_TIMER_DEF(m_battery_timer_id);                                         /**< Battery timer. */
    
    static void battery_level_meas_timeout_handler(void * p_context);
    
    /**@brief Function for the GAP initialization.
    212 
     *
    213 
     * @details This function will set up all the necessary GAP (Generic Access Profile) parameters of
    214 
     *          the device. It also sets the permissions and appearance.
    215 
     */ 
    static void gap_params_init(void)
    {
       uint32_t err_code;
       ble_gap_conn_sec_mode_t     sec_mode;
       BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
       err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME,
    
       strlen(DEVICE_NAME));
     
       APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Struct that contains pointers to the encoded advertising data. */
    static ble_gap_adv_data_t m_adv_data =
    {
        .adv_data =
        {
            .p_data = m_enc_advdata,
            .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
        },
        .scan_rsp_data =
        {
            .p_data = NULL,
            .len    = 0
    
        }
    };
    
    /**@brief Callback function for asserts in the SoftDevice.
     *
     * @details This function will be called in case of an assert in the SoftDevice.
     *
     * @warning This handler is an example only and does not fit a final product. You need to analyze
     *          how your product is supposed to react in case of Assert.
     * @warning On assert from the SoftDevice, the system can only recover on reset.
     * @warning On assert from the SoftDevice, the system can only recover on reset.
     *
     * @param[in]   line_num   Line number of the failing ASSERT call.
     * @param[in]   file_name  File name of the failing ASSERT call.
     */
    void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
    {
        app_error_handler(DEAD_BEEF, line_num, p_file_name);
    }
    
    
    /**@brief Function for handling the ADC interrupt.
     *
     * @details  This function will fetch the conversion result from the ADC, convert the value into
     *           percentage and send it to peer.
     */
    void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            nrf_saadc_value_t adc_result;
            uint16_t batt_lvl_in_milli_volts;
            uint8_t percentage_batt_lvl;
            uint32_t err_code;
    
            adc_result = p_event->data.done.p_buffer[0];
    
            batt_lvl_in_milli_volts =
            ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    
            NRF_LOG_INFO("Battery Level Measurement : %d [mV]", batt_lvl_in_milli_volts);
            if(batt_lvl_in_milli_volts != 0)
            {        
              remote_led_indication = batt_lvl_in_milli_volts;
            }
        }
        else if (p_event->type == NRF_DRV_SAADC_EVT_CALIBRATEDONE)
        {
            nrf_delay_ms(1);
            battery_level_meas_timeout_handler(NULL);
            NRF_LOG_INFO("SAADC calibration complete");
        }
    }
    
    
    /**@brief Function for handling the Battery measurement timer timeout.
     *
     * @details This function will be called each time the battery level measurement timer expires.
     *
     * @param[in] p_context  Pointer used for passing some arbitrary information (context) from the
     *                       app_start_timer() call to the timeout handler.
     */
    static void battery_level_meas_timeout_handler(void * p_context)
    {
        UNUSED_PARAMETER(p_context);
        
        ret_code_t err_code = nrf_drv_saadc_buffer_convert(&m_adc_buf, 1);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_saadc_sample();
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for initializing the Advertising functionality.
     *
     * @details Encodes the required advertising data and passes it to the stack.
     *          Also builds a structure to be passed to the stack when starting advertising.
     */
    static void advertising_data_update(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
        ble_advdata_manuf_data_t manuf_specific_data;
    
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
        manuf_specific_data.data.p_data = (uint8_t *) &packet_buf;
        manuf_specific_data.data.size   = sizeof(packet_buf);
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_FULL_NAME;
        advdata.flags                 = flags;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
    
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = 400;       // Broadcast for 4 sec.
    
        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for starting advertising.
     */
    static void advertising_start(void)
    {
       ret_code_t err_code;
    
        err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
        APP_ERROR_CHECK(err_code);
        printf("led_indication = %d\n\r", remote_led_indication);
    
    /**** LED indication while advertising ****/
        if (remote_led_indication <= 1920)
       {
            nrf_gpio_pin_write(LED_1, LOW);   // Green Led will Blink on less than 10% battery
            nrf_delay_ms(50);
    
            nrf_gpio_pin_write(LED_1, HIGH);
            nrf_delay_ms(50);
     
            NRF_LOG_INFO("More than 10 percent battery level");
        }
    
        if (remote_led_indication > 1920)
        {
            nrf_gpio_pin_write(LED_2, LOW);   // Red Led will Blink on more than 10% battery 
            nrf_delay_ms(50); 
    
            nrf_gpio_pin_write(LED_2, HIGH);   
            nrf_delay_ms(50);
    
            NRF_LOG_INFO("Less than 10 percent battery level");
        }
    }
    
    /**@brief Function for starting advertising.
     */
    static void advertising_stop()
    {
        ret_code_t err_code;
     
        err_code = sd_ble_gap_adv_stop(m_adv_handle);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for initializing the BLE stack.
     *
     * @details Initializes the SoftDevice and the BLE event interrupt.
     */
    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for handling bsp events.
     */
    
    void bsp_evt_handler(bsp_event_t evt)
    {
        switch (evt) 
        {
              case BSP_EVENT_KEY_0:
              packet_buf[0] = BSP_EVENT_KEY_0;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_1: 
              packet_buf[0] = BSP_EVENT_KEY_1;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_2: 
              packet_buf[0] = BSP_EVENT_KEY_2;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_3: 
              packet_buf[0] = BSP_EVENT_KEY_3;
              packet_buf[1]++;
              break;
     
              case BSP_EVENT_KEY_4: 
              packet_buf[0] = BSP_EVENT_KEY_4;
              packet_buf[1]++;
              break;
              
              case BSP_EVENT_KEY_5:
              packet_buf[0] = BSP_EVENT_KEY_5;
              packet_buf[1]++;
              break;
      
              case BSP_EVENT_KEY_6: 
              packet_buf[0] = BSP_EVENT_KEY_6;
              packet_buf[1]++;
              break;
          
              case BSP_EVENT_KEY_7:
              packet_buf[0] = BSP_EVENT_KEY_7;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_8: 
              packet_buf[0] = BSP_EVENT_KEY_8;
              packet_buf[1]++;
              break; 
    
              case BSP_EVENT_KEY_9: 
              packet_buf[0] = BSP_EVENT_KEY_9;
              packet_buf[1]++;
              break;
          
              case BSP_EVENT_KEY_10:
              packet_buf[0] = BSP_EVENT_KEY_10;
              packet_buf[1]++;
              break;
      }
        (void)sd_ble_gap_adv_stop(m_adv_handle);
        advertising_data_update();
        advertising_start();
    }
    
    /**@brief Function for initializing LEDs. */
    static void leds_init(void)
    {
        ret_code_t err_code = bsp_init(BSP_INIT_LEDS, NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for initializing timers. */
    static void timers_init(void)
    {
        ret_code_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
     
        // Create timers.
        err_code = app_timer_create(&m_battery_timer_id,
                                    APP_TIMER_MODE_REPEATED,
                                    battery_level_meas_timeout_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for starting application timers.
     */
    static void application_timers_start(void)
    {
        ret_code_t err_code;
    
        // Start application timers.
        err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for initializing power management.
     */
    static void power_management_init(void)
    {
        ret_code_t err_code;
        err_code = nrf_pwr_mgmt_init();
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for configuring ADC to do battery level conversion.
     */
    static void adc_configure(void)
    {
        ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_saadc_channel_config_t config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
    
        config.burst = NRF_SAADC_BURST_ENABLED;
    
        err_code = nrf_drv_saadc_channel_init(0, &config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_calibrate_offset();
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for handling the idle state (main loop).
     *
     * @details If there is no pending log operation, then sleep until next the next event occurs.
     */
    static void idle_state_handle(void)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }
    
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        // Initialize.
        timers_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        (void)sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
        advertising_data_update();
        leds_init();
    
        uint8_t err_code = NRF_SUCCESS;
    	
        err_code = bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler);
    
        //err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        adc_configure();
    
        // Start execution.
        NRF_LOG_INFO("Beacon example started.");
        application_timers_start();
        advertising_start();
    
        // Enter main loop.
        for (;; )
        {
            idle_state_handle();
        }
    }
    
    
    /**
     * @}
     */

    I would appreciate soon response so that I could get low power mode. 

    Thanks

     

Reply
  • Hi !!

    You need to ask the sensor producers what commands to use to read and write to the values that you are trying to acheive

    I got this and was able to use read and write function properly. I was getting ~1.2uA when I used only initializing twi_init(); nrf_drv_twi_tx(); & nrf_drv_twi_rx(); 

    After adding this to my original code in modified ble_app_beacon example, the current consumption increased to ~1.2mA. I also tried with disabling other functions such as ble stack, advertising and the current consumption gets lower to ~400uA. After debugging I found that nrf52832 chip isn't going to sleep mode. 

    I am attaching my main.c below so that you could suggest why nrf52832 chip is not going to sleep mode.

    /**
     * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     *
     * @defgroup ble_sdk_app_beacon_main main.c
     * @{
     * @ingroup ble_sdk_app_beacon
     * @brief Beacon Transmitter Sample Application main file.
     *
     * This file contains the source code for an Beacon transmitter sample application.
     */
    
    /******** Ble_beacon_remote **********/
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "nordic_common.h"
    #include "bsp.h"
    #include "nrf_soc.h"
    #include "nrf_sdh.h"
    #include "nrf_sdh_ble.h"
    #include "ble_advdata.h"
    #include "app_timer.h"
    #include "nrf_pwr_mgmt.h"
    #include "nrf_drv_clock.h"
    #include "nrf_drv_saadc.h"
    #include "nrf_drv_ppi.h"
    #include "nrf_drv_timer.h"
    #include "boards.h"
    #include "nrf.h"
    #include "nrf_delay.h"
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #define DEVICE_NAME                     "DeviceName"
    #define APP_BLE_CONN_CFG_TAG            1                                  /**< A tag identifying the SoftDevice BLE configuration. */
    
    #define BATTERY_LEVEL_MEAS_INTERVAL     APP_TIMER_TICKS(5000)              /**< Battery level measurement interval (ticks). */
    
    #define NON_CONNECTABLE_ADV_INTERVAL    MSEC_TO_UNITS(400, UNIT_0_625_MS)  /**< The advertising interval for non-connectable advertisement (100 ms). This value can vary between 100ms to 10.24s). */
    
    #define APP_BEACON_INFO_LENGTH          0x17                               /**< Total length of information advertised by the Beacon. */
    #define APP_ADV_DATA_LENGTH             0x15                               /**< Length of manufacturer specific data in the advertisement. */
    #define APP_DEVICE_TYPE                 0x02                               /**< 0x02 refers to Beacon. */
    #define APP_COMPANY_IDENTIFIER          0x0059  
    
    
    #define ADC_REF_VOLTAGE_IN_MILLIVOLTS   600                               /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
    #define ADC_PRE_SCALING_COMPENSATION    6                                 /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
    #define DIODE_FWD_VOLT_DROP_MILLIVOLTS  270                               /**< Typical forward voltage drop of the diode . */
    #define ADC_RES_10BIT                   1024                              /**< Maximum digital value for 10-bit ADC conversion. */
    
    volatile uint16_t remote_led_indication;
    //static uint8_t      packet_buf;          /****** TX buffer for buttons ******/
    static uint8_t      packet_buf[2];          /****** TX buffer for buttons ******/
    
    /**@brief Macro to convert the result of ADC conversion in millivolts.
     *
     * @param[in]  ADC_VALUE   ADC result.
     *
     * @retval     Result converted to millivolts.
     */
    #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
            ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / ADC_RES_10BIT) * ADC_PRE_SCALING_COMPENSATION)
    
    #define DEAD_BEEF                       0xDEADBEEF                         /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
    #define HIGH        1
    #define LOW         0
    
    static ble_gap_adv_params_t m_adv_params;                                  /**< Parameters to be passed to the stack when starting advertising. */
    static uint8_t              m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; /**< Advertising handle used to identify an advertising set. */
    static uint8_t              m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];  /**< Buffer for storing an encoded advertising set. */
    
    static nrf_saadc_value_t m_adc_buf;
    
    APP_TIMER_DEF(m_battery_timer_id);                                         /**< Battery timer. */
    
    static void battery_level_meas_timeout_handler(void * p_context);
    
    /**@brief Function for the GAP initialization.
    212 
     *
    213 
     * @details This function will set up all the necessary GAP (Generic Access Profile) parameters of
    214 
     *          the device. It also sets the permissions and appearance.
    215 
     */ 
    static void gap_params_init(void)
    {
       uint32_t err_code;
       ble_gap_conn_sec_mode_t     sec_mode;
       BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
       err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME,
    
       strlen(DEVICE_NAME));
     
       APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Struct that contains pointers to the encoded advertising data. */
    static ble_gap_adv_data_t m_adv_data =
    {
        .adv_data =
        {
            .p_data = m_enc_advdata,
            .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX
        },
        .scan_rsp_data =
        {
            .p_data = NULL,
            .len    = 0
    
        }
    };
    
    /**@brief Callback function for asserts in the SoftDevice.
     *
     * @details This function will be called in case of an assert in the SoftDevice.
     *
     * @warning This handler is an example only and does not fit a final product. You need to analyze
     *          how your product is supposed to react in case of Assert.
     * @warning On assert from the SoftDevice, the system can only recover on reset.
     * @warning On assert from the SoftDevice, the system can only recover on reset.
     *
     * @param[in]   line_num   Line number of the failing ASSERT call.
     * @param[in]   file_name  File name of the failing ASSERT call.
     */
    void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name)
    {
        app_error_handler(DEAD_BEEF, line_num, p_file_name);
    }
    
    
    /**@brief Function for handling the ADC interrupt.
     *
     * @details  This function will fetch the conversion result from the ADC, convert the value into
     *           percentage and send it to peer.
     */
    void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            nrf_saadc_value_t adc_result;
            uint16_t batt_lvl_in_milli_volts;
            uint8_t percentage_batt_lvl;
            uint32_t err_code;
    
            adc_result = p_event->data.done.p_buffer[0];
    
            batt_lvl_in_milli_volts =
            ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    
            NRF_LOG_INFO("Battery Level Measurement : %d [mV]", batt_lvl_in_milli_volts);
            if(batt_lvl_in_milli_volts != 0)
            {        
              remote_led_indication = batt_lvl_in_milli_volts;
            }
        }
        else if (p_event->type == NRF_DRV_SAADC_EVT_CALIBRATEDONE)
        {
            nrf_delay_ms(1);
            battery_level_meas_timeout_handler(NULL);
            NRF_LOG_INFO("SAADC calibration complete");
        }
    }
    
    
    /**@brief Function for handling the Battery measurement timer timeout.
     *
     * @details This function will be called each time the battery level measurement timer expires.
     *
     * @param[in] p_context  Pointer used for passing some arbitrary information (context) from the
     *                       app_start_timer() call to the timeout handler.
     */
    static void battery_level_meas_timeout_handler(void * p_context)
    {
        UNUSED_PARAMETER(p_context);
        
        ret_code_t err_code = nrf_drv_saadc_buffer_convert(&m_adc_buf, 1);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_saadc_sample();
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for initializing the Advertising functionality.
     *
     * @details Encodes the required advertising data and passes it to the stack.
     *          Also builds a structure to be passed to the stack when starting advertising.
     */
    static void advertising_data_update(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
        ble_advdata_manuf_data_t manuf_specific_data;
    
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
        manuf_specific_data.data.p_data = (uint8_t *) &packet_buf;
        manuf_specific_data.data.size   = sizeof(packet_buf);
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_FULL_NAME;
        advdata.flags                 = flags;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
    
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
        m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = 400;       // Broadcast for 4 sec.
    
        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for starting advertising.
     */
    static void advertising_start(void)
    {
       ret_code_t err_code;
    
        err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
        APP_ERROR_CHECK(err_code);
        printf("led_indication = %d\n\r", remote_led_indication);
    
    /**** LED indication while advertising ****/
        if (remote_led_indication <= 1920)
       {
            nrf_gpio_pin_write(LED_1, LOW);   // Green Led will Blink on less than 10% battery
            nrf_delay_ms(50);
    
            nrf_gpio_pin_write(LED_1, HIGH);
            nrf_delay_ms(50);
     
            NRF_LOG_INFO("More than 10 percent battery level");
        }
    
        if (remote_led_indication > 1920)
        {
            nrf_gpio_pin_write(LED_2, LOW);   // Red Led will Blink on more than 10% battery 
            nrf_delay_ms(50); 
    
            nrf_gpio_pin_write(LED_2, HIGH);   
            nrf_delay_ms(50);
    
            NRF_LOG_INFO("Less than 10 percent battery level");
        }
    }
    
    /**@brief Function for starting advertising.
     */
    static void advertising_stop()
    {
        ret_code_t err_code;
     
        err_code = sd_ble_gap_adv_stop(m_adv_handle);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for initializing the BLE stack.
     *
     * @details Initializes the SoftDevice and the BLE event interrupt.
     */
    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for handling bsp events.
     */
    
    void bsp_evt_handler(bsp_event_t evt)
    {
        switch (evt) 
        {
              case BSP_EVENT_KEY_0:
              packet_buf[0] = BSP_EVENT_KEY_0;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_1: 
              packet_buf[0] = BSP_EVENT_KEY_1;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_2: 
              packet_buf[0] = BSP_EVENT_KEY_2;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_3: 
              packet_buf[0] = BSP_EVENT_KEY_3;
              packet_buf[1]++;
              break;
     
              case BSP_EVENT_KEY_4: 
              packet_buf[0] = BSP_EVENT_KEY_4;
              packet_buf[1]++;
              break;
              
              case BSP_EVENT_KEY_5:
              packet_buf[0] = BSP_EVENT_KEY_5;
              packet_buf[1]++;
              break;
      
              case BSP_EVENT_KEY_6: 
              packet_buf[0] = BSP_EVENT_KEY_6;
              packet_buf[1]++;
              break;
          
              case BSP_EVENT_KEY_7:
              packet_buf[0] = BSP_EVENT_KEY_7;
              packet_buf[1]++;
              break;
    
              case BSP_EVENT_KEY_8: 
              packet_buf[0] = BSP_EVENT_KEY_8;
              packet_buf[1]++;
              break; 
    
              case BSP_EVENT_KEY_9: 
              packet_buf[0] = BSP_EVENT_KEY_9;
              packet_buf[1]++;
              break;
          
              case BSP_EVENT_KEY_10:
              packet_buf[0] = BSP_EVENT_KEY_10;
              packet_buf[1]++;
              break;
      }
        (void)sd_ble_gap_adv_stop(m_adv_handle);
        advertising_data_update();
        advertising_start();
    }
    
    /**@brief Function for initializing LEDs. */
    static void leds_init(void)
    {
        ret_code_t err_code = bsp_init(BSP_INIT_LEDS, NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for initializing timers. */
    static void timers_init(void)
    {
        ret_code_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
     
        // Create timers.
        err_code = app_timer_create(&m_battery_timer_id,
                                    APP_TIMER_MODE_REPEATED,
                                    battery_level_meas_timeout_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for starting application timers.
     */
    static void application_timers_start(void)
    {
        ret_code_t err_code;
    
        // Start application timers.
        err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for initializing power management.
     */
    static void power_management_init(void)
    {
        ret_code_t err_code;
        err_code = nrf_pwr_mgmt_init();
        APP_ERROR_CHECK(err_code);
    }
    
    /**@brief Function for configuring ADC to do battery level conversion.
     */
    static void adc_configure(void)
    {
        ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_saadc_channel_config_t config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);
    
        config.burst = NRF_SAADC_BURST_ENABLED;
    
        err_code = nrf_drv_saadc_channel_init(0, &config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_calibrate_offset();
        APP_ERROR_CHECK(err_code);
    }
    
    
    /**@brief Function for handling the idle state (main loop).
     *
     * @details If there is no pending log operation, then sleep until next the next event occurs.
     */
    static void idle_state_handle(void)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }
    
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        // Initialize.
        timers_init();
        power_management_init();
        ble_stack_init();
        gap_params_init();
        (void)sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
        advertising_data_update();
        leds_init();
    
        uint8_t err_code = NRF_SUCCESS;
    	
        err_code = bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler);
    
        //err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        adc_configure();
    
        // Start execution.
        NRF_LOG_INFO("Beacon example started.");
        application_timers_start();
        advertising_start();
    
        // Enter main loop.
        for (;; )
        {
            idle_state_handle();
        }
    }
    
    
    /**
     * @}
     */

    I would appreciate soon response so that I could get low power mode. 

    Thanks

     

Children
  • techietech said:
    After debugging I found that nrf52832 chip isn't going to sleep mode. 

     What sleep mode? System on or system off?

    If system off: Where do you put it in system off mode?

    if system on: are you sure? How do you determine this?

  •  What sleep mode? System on or system off?

    System OFF Sleep Mode 

    If system off: Where do you put it in system off mode?

    sdk_config.h 

    // <e> NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED - Enable standby timeout.
    //==========================================================
    #ifndef NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
    #define NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED 1
    #endif
    // <o> NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S - Standby timeout (in seconds). 
    // <i> Shutdown procedure will begin no earlier than after this number of seconds.
    
    #ifndef NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S
    #define NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_S 20
    #endif

    I managed to solve that issue. I just changed the pull up into pull down configuration and it is going to deep sleep mode (cypress capsense)  and system OFF sleep mode in nrf52832.

    But our custom board has pull up capsense button so cypress chip will not go into deep sleep mode until I need to pull down it but if I do so it won't work as it needs active low signal to get interrupt from capsense buttons. So any suggestion how could I do that ?

    Secondly, if I put capsense IC into deep sleep mode and so I need to wakeup by giving low signal to attention pin but in deep sleep mode capsense won't work and nrf52832 will be stay in sytem OFF sleep until it gets interrupt. So any suggestion how to wakeup the nrf52832 sot that it could give active low signal to attention pin? 

    thanks

  • techietech said:
    But our custom board has pull up capsense button so cypress chip will not go into deep sleep mode until I need to pull down it but if I do so it won't work as it needs active low signal to get interrupt from capsense buttons. So any suggestion how could I do that ?

     Not sure I understand the issue. But you can put whatever pull configuration on the pins. I am no HW expert, but do you mean that you have an external pull up resistor on your custom PCB?

Related