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

nRF52832 ble beacon integrate with Temp sensor using TWI

I have the nRF52 Kit with me. iam using SES IDE and downloaded the SDK nRF5_SDK_17.0.0_9d13099. I am using Windows 10 OS in my Laptop.

There inside example\ble_peripheral\ble_app_beacon, I am incorporating another example. The TWI sensor example as I am using MAX3020 Temp sensor to talk to nRF52832 chip. I am able to read the Temp value via TWI, but not able to beacon the temp values.

In my main.c, there is a function called "ble_advdata_set(&advdata, 0)", which has no definition in the driver file ble_advdata.c.

Can you provide me an alternative to the function as that is the reason that the data is not beaconed out periodically.

/**************************** main.c **********************************/

/**
* 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.
*/

#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_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#include "boards.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"
/***
PRIVATE FUNCTIONS
****/
void set_adv_data(bool);

#define APP_BLE_CONN_CFG_TAG 1 /**< A tag identifying the SoftDevice BLE configuration. */

#define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS) /**< The advertising interval for non-connectable advertisement (100 ms). This value can vary between 100ms to 10.24s). */
#define BEACON_INTERVAL APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER)
#define APP_TIMER_PRESCALER 0
#define APP_TIMER_OP_QUEUE_SIZE 4
#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_MEASURED_RSSI 0xC3 /**< The Beacon's measured RSSI at 1 meter distance in dBm. */
#define APP_COMPANY_IDENTIFIER 0x0059 /**< Company identifier for Nordic Semiconductor ASA. as per www.bluetooth.org. */
#define APP_MAJOR_VALUE 0x01, 0x02 /**< Major value used to identify Beacons. */
#define APP_MINOR_VALUE 0x03, 0x04 /**< Minor value used to identify Beacons. */
#define APP_BEACON_UUID 0x01, 0x12, 0x23, 0x34, \
0x45, 0x56, 0x67, 0x78, \
0x89, 0x9a, 0xab, 0xbc, \
0xcd, 0xde, 0xef, 0xf0 /**< Proprietary UUID for Beacon. */

//#define APP_BEACON_UUID 0x00,0x00,0x00,0x00, \
// 0x00,0x00,0x00,0x00, \
// 0x00,0x00,0x00,0x00, \
// 0x00,0x00,0x00,0x00

#define DEAD_BEEF 0xDEADBEEF /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */


#if defined(USE_UICR_FOR_MAJ_MIN_VALUES)
#define MAJ_VAL_OFFSET_IN_BEACON_INFO 18 /**< Position of the MSB of the Major Value in m_beacon_info array. */
#define UICR_ADDRESS 0x10001080 /**< Address of the UICR register used by this example. The major and minor versions to be encoded into the advertising data will be picked up from this location. */
#endif

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. */

/**@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

}
};


static uint8_t m_beacon_info[APP_BEACON_INFO_LENGTH] = /**< Information advertised by the Beacon. */
{
APP_DEVICE_TYPE, // Manufacturer specific information. Specifies the device type in this
// implementation.
APP_ADV_DATA_LENGTH, // Manufacturer specific information. Specifies the length of the
// manufacturer specific data in this implementation.
APP_BEACON_UUID, // 128 bit UUID value.
APP_MAJOR_VALUE, // Major arbitrary value that can be used to distinguish between Beacons.
APP_MINOR_VALUE, // Minor arbitrary value that can be used to distinguish between Beacons.
APP_MEASURED_RSSI // Manufacturer specific information. The Beacon's measured TX power in
// this implementation.

};


/**@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.
*
* @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 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_init(void)
{
#if 1
uint32_t err_code;
ble_advdata_t advdata;
uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

ble_advdata_manuf_data_t manuf_specific_data;


manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
ble_gap_conn_sec_mode_t sec_mode;

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

#if defined(USE_UICR_FOR_MAJ_MIN_VALUES)
// If USE_UICR_FOR_MAJ_MIN_VALUES is defined, the major and minor values will be read from the
// UICR instead of using the default values. The major and minor values obtained from the UICR
// are encoded into advertising data in big endian order (MSB First).
// To set the UICR used by this example to a desired value, write to the address 0x10001080
// using the nrfjprog tool. The command to be used is as follows.
// nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val <your major/minor value>
// For example, for a major value and minor value of 0xabcd and 0x0102 respectively, the
// the following command should be used.
// nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val 0xabcd0102
uint16_t major_value = ((*(uint32_t *)UICR_ADDRESS) & 0xFFFF0000) >> 16;
uint16_t minor_value = ((*(uint32_t *)UICR_ADDRESS) & 0x0000FFFF);

uint8_t index = MAJ_VAL_OFFSET_IN_BEACON_INFO;

m_beacon_info[index++] = MSB_16(major_value);
m_beacon_info[index++] = LSB_16(major_value);

m_beacon_info[index++] = MSB_16(minor_value);
m_beacon_info[index++] = LSB_16(minor_value);
#endif
// Temp_sensor_data();
// uint8_t index = MAJ_VAL_OFFSET_IN_BEACON_INFO;
// m_beacon_info[index++] = m_sample[0];
// m_beacon_info[index++] = m_sample[1];

manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
manuf_specific_data.data.size = APP_BEACON_INFO_LENGTH;

// Build and set advertising data.
memset(&advdata, 0, sizeof(advdata));

advdata.name_type = BLE_ADVDATA_NO_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 = 0; // Never time out.

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);
#endif
#if 0
uint32_t err_code;
const char DEVICE_NAME = "nRF52832";

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);

set_adv_data(true);

// Initialize advertising parameters (used when starting advertising).
memset(&m_adv_params, 0, sizeof(m_adv_params));

//m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
m_adv_params.p_peer_addr = NULL; // Undirected advertisement.
//m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
m_adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval = NON_CONNECTABLE_ADV_INTERVAL;
//m_adv_params.timeout = APP_CFG_NON_CONN_ADV_TIMEOUT;
m_adv_params.duration = 0; //APP_CFG_NON_CONN_ADV_TIMEOUT;

err_code = ble_advdata_encode(&m_adv_data, 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);
#endif
}


/**@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);

err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
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 initializing logging. */
static void log_init(void)
{
ret_code_t err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);

NRF_LOG_DEFAULT_BACKENDS_INIT();
}

/**@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);
}


/**@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 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();
}
}

/*
* The following functions are of TWI Temp sensor
*
*/
/*********************************************************************************************************/
/* TWI instance ID. */
#define TWI_INSTANCE_ID 0

/* Common addresses definition for temperature sensor. */
#define LM75B_ADDR (0x90U >> 1)

#define LM75B_REG_TEMP 0x00U
#define LM75B_REG_CONF 0x01U
#define LM75B_REG_THYST 0x02U
#define LM75B_REG_TOS 0x03U

/* Mode for LM75B. */
#define NORMAL_MODE 0U

/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;


uint16_t tempVal;
float tempC;
/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

/* Buffer for samples read from temperature sensor. */
static uint8_t m_sample[2];

/**
* @brief Function for setting active mode on MMA7660 accelerometer.
*/
void LM75B_set_mode(void)
{
ret_code_t err_code;

/* Writing to LM75B_REG_CONF "0" set temperature sensor in NORMAL mode. */
uint8_t reg[2] = {LM75B_REG_CONF, NORMAL_MODE};
err_code = nrf_drv_twi_tx(&m_twi, LM75B_ADDR, reg, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);

/* Writing to pointer byte. */
reg[0] = LM75B_REG_TEMP;
m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, LM75B_ADDR, reg, 1, false);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
}

/**
* @brief Function for handling data from temperature sensor.
*
* @param[in] temp Temperature in Celsius degrees read from sensor.
*/
__STATIC_INLINE void data_handler(uint8_t temp)
{
NRF_LOG_INFO("Temperature: %d Celsius degrees.", temp);
}

/**
* @brief TWI events handler.
*/
void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
switch (p_event->type)
{
case NRF_DRV_TWI_EVT_DONE:
if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
{
tempVal = (m_sample[0] << 8 | m_sample[1]);
tempC = tempVal * 0.00390625;

// tempC = ((((int16_t)m_sample[0] << 8) | m_sample[1]) / 32);

//NRF_LOG_INFO("Temperature: %d Celsius degrees.", tempC);
//NRF_LOG_INFO("Temperature: " "%s%d.%03d", NRF_LOG_FLOAT(tempC));
//printf("Temperature: " "%s%d.%03d\n", NRF_LOG_FLOAT(tempC));

}
m_xfer_done = true;
break;
default:
break;
}
}

/**
* @brief UART initialization.
*/
void twi_init (void)
{
ret_code_t err_code;

const nrf_drv_twi_config_t twi_lm75b_config = {
.scl = ARDUINO_SCL_PIN,
.sda = ARDUINO_SDA_PIN,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};

err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&m_twi);
}

/**
* @brief Function for reading data from temperature sensor.
*/
static void read_sensor_data()
{
m_xfer_done = false;

/* Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. */
ret_code_t err_code = nrf_drv_twi_rx(&m_twi, LM75B_ADDR, m_sample, sizeof(m_sample));
APP_ERROR_CHECK(err_code);
}
/******************************************************************************************************/
// one-shot flag for setting adv data
static volatile bool g_setAdvData = false;

/**@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 beacon_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
// set update data flag
g_setAdvData = true;
}
/******************************* My Temperature Sensor data **************************************/
void Temp_sensor_data()
{
ret_code_t err_code_local;

do
{
__WFE();
}while (m_xfer_done == false);

// read_sensor_data();
//
// registr[0] = 0x00U;
// nrf_drv_twi_tx(&m_twi, 0x48U, registr, sizeof(registr), false);
// while (m_xfer_done == false);
// m_xfer_done = false;
// m_sample = 0U;
// nrf_drv_twi_rx(&m_twi, 0x48U, &m_sample, sizeof(m_sample));

m_xfer_done = false;
uint8_t reg[2] = {0x00U};
err_code_local = nrf_drv_twi_tx(&m_twi, 0x48U, reg, sizeof(reg), true);
APP_ERROR_CHECK(err_code_local);
while (m_xfer_done == false);
nrf_delay_ms(5);


m_xfer_done = false;
ret_code_t err_code1 = nrf_drv_twi_rx(&m_twi, 0x48U, m_sample, sizeof(m_sample));
APP_ERROR_CHECK(err_code1);
while (m_xfer_done == false)
// m_xfer_done = false;
// ret_code_t err_code2 = nrf_drv_twi_rx(&m_twi, 0x48U, &m_sample, sizeof(m_sample));
// APP_ERROR_CHECK(err_code2);
// while (m_xfer_done == false)


NRF_LOG_FLUSH();
// printf("After Reading the Temperature Sensor\n");

}
/******************************************************************************************************/
static void power_manage(void)
{
uint32_t err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);
}

// set adv data
void set_adv_data(bool init)
{
uint32_t err_code;

ble_advdata_t advdata;
uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

ble_advdata_manuf_data_t manuf_data; // Variable to hold manufacturer specific data
// Initialize with easily identifiable data
uint8_t data[] = {
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
0xb1, 0xb2, 0xb3, 0xb4
};

// get sensor data
if (!init) {
// get T/H
//uint16_t temp_val, humid_val;
//HDC1010_get_temp_raw(&temp_val);
//data[0] = temp_val >> 8;
//data[1] = temp_val;

Temp_sensor_data();

#if 0
HDC1010_get_humid_raw(&humid_val);
data[2] = humid_val >> 8;
data[3] = humid_val;
// get ambient light value
uint16_t adc_ch0, adc_ch1;
APDS9301_read_adc_data(&adc_ch0, &adc_ch1);
data[4] = adc_ch0 >> 8;
data[5] = adc_ch0;
data[6] = adc_ch1 >> 8;
data[7] = adc_ch1;
#endif
}
//m_sample[0] = 'T'; m_sample[1] = 'B';

manuf_data.company_identifier = 0x0000;
//manuf_data.data.p_data = data; // Original code
manuf_data.data.p_data = m_sample;
manuf_data.data.size = sizeof(m_sample);

// Build advertising data struct to pass into @ref ble_advertising_init.
memset(&advdata, 0, sizeof(advdata));

advdata.name_type = BLE_ADVDATA_SHORT_NAME;
advdata.short_name_len = 5;
advdata.flags = flags; //BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
advdata.p_manuf_specific_data = &manuf_data;
// if you don't set tx power, you get 3 extra bytes for manuf data
//int8_t tx_power = -4;
//advdata.p_tx_power_level = &tx_power;
advdata.include_appearance = true;

//err_code = ble_advdata_set(&advdata, 0);
//APP_ERROR_CHECK(err_code);
err_code = ble_advdata_encode(&advdata,&manuf_data,sizeof(advdata));
APP_ERROR_CHECK(err_code);
//err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
// APP_ERROR_CHECK(err_code);


}


/**
* @brief Function for application main entry.
*/
int main(void)
{
// Initialize.
uint32_t err_code;
err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);

log_init();
timers_init();
leds_init();
//power_management_init(); // Commented to be alligned with the internet code
ble_stack_init();
advertising_init();

// Start execution.
NRF_LOG_INFO("Beacon example started.");
printf("Beacon example started\n");
advertising_start();
twi_init();
//printf("TWI_INIT done\n");
LM75B_set_mode();
//printf("LM75B_set_mode done\n");

/**********************************************/
// Enter main loop.
for (;; )
{
//idle_state_handle();
if(!g_setAdvData) {
//printf("Inside IF\n");
set_adv_data(false); //original code

//set_adv_data(true); //Just experimentation
//g_setAdvData = false;
}

//power_management_init();
power_manage();
printf("Temperature: " "%s%d.%03d\n", NRF_LOG_FLOAT(tempC));


}
}
/********************************************/
#if 0
while (true)
{
nrf_delay_ms(500);

do
{
__WFE();
}while (m_xfer_done == false);

// read_sensor_data();
//
// registr[0] = 0x00U;
// nrf_drv_twi_tx(&m_twi, 0x48U, registr, sizeof(registr), false);
// while (m_xfer_done == false);
// m_xfer_done = false;
// m_sample = 0U;
// nrf_drv_twi_rx(&m_twi, 0x48U, &m_sample, sizeof(m_sample));

m_xfer_done = false;
uint8_t reg[2] = {0x00U};
err_code = nrf_drv_twi_tx(&m_twi, 0x48U, reg, sizeof(reg), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
nrf_delay_ms(5);




m_xfer_done = false;
ret_code_t err_code1 = nrf_drv_twi_rx(&m_twi, 0x48U, m_sample, sizeof(m_sample));
APP_ERROR_CHECK(err_code1);
while (m_xfer_done == false)
// m_xfer_done = false;
// ret_code_t err_code2 = nrf_drv_twi_rx(&m_twi, 0x48U, &m_sample, sizeof(m_sample));
// APP_ERROR_CHECK(err_code2);
// while (m_xfer_done == false)


NRF_LOG_FLUSH();

}
#endif

  

Parents Reply Children
No Data
Related