Hi, I'm using NXP LM75B temprature sensor based on nRF SDK's example code.
I would like to save power on this sensor.
I have prepared the code as follows:
/* Mode for LM75B. */ #define LM75B_MODE_NORMAL 0U #define LM75B_MODE_SHUTDOWN 1U // Add
/**
* @brief Function for setting sleep mode on LM75B temperature sensor.
*/
void LM75B_sdn_mode(void)
{
ret_code_t err_code;
/* Writing to LM75B_REG_CONF "1" set temperature sensor in SHUTDOWN mode. */
uint8_t reg[2] = {LM75B_REG_CONF, LM75B_MODE_SHUTDOWN};
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);
}
Following main() is work fine:
/**@brief Function for application main entry.
*/
int main(void)
{
uint32_t err_code;
LmHandlerErrorStatus_t lm_Error_code;
// Initialize logs.
log_init();
NRF_LOG_INFO("LoRaWan end-device started.");
// Initialize clocks & power
nrf_drv_clock_init();
nrf_drv_clock_lfclk_request(NULL);
nrf_pwr_mgmt_init();
// Enable nRF52 DCDC
NRF_POWER->DCDCEN = 1;
// Initialize Scheduler and timer
timers_init();
// Initialize NVM
NvmDataMgmtInit();
// Initialize TWI
twi_init();
// Initialize LM75B
LM75B_set_mode();
nrf_delay_ms(200);
// Initialize LoRa chip.
err_code = lora_hardware_init();
APP_ERROR_CHECK(err_code);
// Initialize transmission periodicity variable
TxPeriodicity = APP_TX_DUTYCYCLE + randr(-APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND);
// Initialize LoRaWan
lm_Error_code = LmHandlerInit(&LmHandlerCallbacks, &LmHandlerParams);
APP_ERROR_CHECK_BOOL(lm_Error_code == LORAMAC_HANDLER_SUCCESS);
// Set system maximum tolerated rx error in milliseconds
LmHandlerSetSystemMaxRxError(20);
// The LoRa-Alliance Compliance protocol package should always be initialized and activated.
LmHandlerPackageRegister(PACKAGE_ID_COMPLIANCE, &LmhpComplianceParams);
// Start Join procedure
LmHandlerJoin();
StartTxProcess(LORAMAC_HANDLER_TX_ON_TIMER);
// Enter main loop.
for (;;)
{
// Process the LoRaMac events
LmHandlerProcess();
// Process application uplinks management
UplinkProcess();
// Process events managed by the scheduler
app_sched_execute();
if (IsMacProcessPending == 1)
{
// Clear flag and prevent MCU to go into low power modes.
IsMacProcessPending = 0;
}
else
{
if (NRF_LOG_PROCESS() == false)
{
nrf_pwr_mgmt_run();
}
}
}
}
And the following code is also work fine (This is only a function test. No sensor is used.):
// Initialize LM75B
// LM75B_set_mode();
// nrf_delay_ms(200);
LM75B_sdn_mode();
nrf_delay_ms(200);
But the following code stops with some error. (Normal mode -> Shutdown mode transition test.):
// Initialize LM75B
LM75B_set_mode();
nrf_delay_ms(200);
LM75B_sdn_mode();
nrf_delay_ms(200);
I don't think the problem is caused by AD conversion timing since I put in 200mSec weighting.
I believe I am making a basic oversight. Do you know what the problem is?
thanks,
tyro