Hi,
I am working with MLX90615 sensor and is working with nrf_drv_twi functions and I could collect data as well. Now I need to put the sensor to sleep mode. Entering to sleep mode is given below.
I would like to collect the data from the sensor, put the sensor to sleep, send the collected value through BLE wait for 5-10 seconds, wake up the sensor and repeat the steps.
The main function I have written is as below.
while(1){
reg=0x27;
err_code=nrf_drv_twi_tx(&twi_instance, 0x5B, ®, sizeof(reg), true); // sending register
m_xfer_done=false;
if(device_found == true) // happens at TWI handler
{
device_found=false;
err_code = ble_nus_string_send(&m_nus, Obj_temp, sizeof(Obj_temp));
// MLX_SLEEP();
nrf_delay_ms(200);
// nrf_delay_ms(2000);
// nrf_delay_ms(2000);
// MLX_WAKEUP();
// nrf_delay_ms(200);
}
reg=0xc6; // sleep command
err_code=nrf_drv_twi_tx(&twi_instance, 0x5B, ®, sizeof(reg), true); // sending register
nrf_delay_ms(2000);
nrf_delay_ms(2000);
nrf_drv_twi_disable(&twi_instance); // disable
nrf_gpio_cfg_output(DEVICE_SCL_PIN); // keep SCL pin high during sleep
nrf_gpio_pin_set(DEVICE_SCL_PIN);
// wake up the sensor
nrf_gpio_pin_clear(DEVICE_SCL_PIN); //make the pin LOW
nrf_delay_ms(40); // wait for some time
nrf_gpio_cfg_input(DEVICE_SCL_PIN,NRF_GPIO_PIN_PULLUP); //enable pull up
nrf_gpio_input_disconnect(DEVICE_SCL_PIN); // disconnect gpio
twi_init(); // initialise twi
nrf_delay_ms(40);
}
Twi initialisation is given below.
void twi_init (void)
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_config = {
.scl = DEVICE_SCL_PIN,
.sda = DEVICE_SDA_PIN,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
err_code = nrf_drv_twi_init(&twi_instance, &twi_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&twi_instance);
}
Is there anything that I am missing because this code is not working. It is going to sleep but not waking up.