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

TWI Low power mode

Dear Nordic Team,

Thanks for support

Currently i am work with VL53L0X in ble_uart_app example. it working fine , but its take 5ma current. How can i use TWI in low power mode. Please suggest anyone.

SDK =12.3.0 , SD=s132. 

My Code :  

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_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

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

    nrf_drv_twi_enable(&m_twi);
}


int main(void)
{
    uint32_t err_code;
    bool erase_bonds;
     uint8_t LI8u_Buffer[50]={0};
		static uint8_t data_array[20]={"Distance===>0000MM\n"};
    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    //uart_init();
	   //==============================================================
	
//			twi_init();
//			if(VL53L0X_init(1)){VL53L0X_Init_flag=1;}
//			else VL53L0X_Init_flag = 0;	

//			VL53L0X_setSignalRateLimit(0.1);
//			VL53L0X_setVcselPulsePeriod(VcselPeriodPreRange,18);
//			VL53L0X_setVcselPulsePeriod(VcselPeriodFinalRange,14);
//			VL53L0X_setMeasurementTimingBudget(220000);
			
			//============================================================
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();

   // printf("\r\nUART Start!\r\n");
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // Enter main loop.
    for (;;)
    {
			 // nrf_delay_ms(5000);
        power_manage();
			  if(m_conn_handle != BLE_CONN_HANDLE_INVALID)
				{	
					Read_Sensor();
						data_array[12]='0'+(Distance/1000);
						data_array[13]='0'+(Distance/100)%10;
						data_array[14]='0'+(Distance/10)%10;
						data_array[15]='0'+(Distance%10);
					if(VL53L0X_Init_flag){
					err_code=ble_nus_string_send(&m_nus,(uint8_t *)"INIT OK",7);			
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
							}
					  err_code=ble_nus_string_send(&m_nus,data_array,sizeof(data_array));			
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
									nrf_delay_ms(500);
				}					
    }
}
void Read_Sensor(void){
				twi_init();nrf_delay_ms(5);
			if(VL53L0X_init(1)){VL53L0X_Init_flag=1;}
			else VL53L0X_Init_flag = 0;	nrf_delay_ms(5);
//VL53L0X_Init_flag=1;
			VL53L0X_setSignalRateLimit(0.1);
			VL53L0X_setVcselPulsePeriod(VcselPeriodPreRange,18);
			VL53L0X_setVcselPulsePeriod(VcselPeriodFinalRange,14);
			VL53L0X_setMeasurementTimingBudget(220000);
	nrf_delay_ms(500);
						 Distance = VL53L0X_readRangeSingleMillimeters();
						 if( Distance<=2000 && Distance>0 )
						 {	
							 Dist_Values=Distance;
						//	 printf("Distance=%d\r\n",Dist_Values);
						 }else{
							 if(Distance!=0&&Distance!=65535){
								    if(Distance>=2000 &&Distance <=8000){
											Dist_Values=1999;
										}
										else if(Distance>=8000 && Distance <=9000){
											Dist_Values=1999;
										}
							 }
					//		printf("Distance Error=%d\r\n",Distance);
						 }
						 						 	nrf_drv_twi_disable(&m_twi);	nrf_delay_ms(5);
							nrf_drv_twi_uninit(&m_twi);nrf_delay_ms(5);
	
	*(volatile uint32_t *)0x40003FFC = 0;
	*(volatile uint32_t *)0x40003FFC;
	*(volatile uint32_t *)0x40003FFC = 1;
						 
}

Parents
  • you need to take care when using the drivers in blocking mode as the nrf_delay_ms() functions are implemented as asm NOP instructions and it will therefore not put the CPU to sleep. If you want to sleep while waiting you need to set up an RTC to time out after the given timout period and put the CPU to sleep with the following calls:
    __WFE();

    __SEV();

    __WFE();.  

Reply
  • you need to take care when using the drivers in blocking mode as the nrf_delay_ms() functions are implemented as asm NOP instructions and it will therefore not put the CPU to sleep. If you want to sleep while waiting you need to set up an RTC to time out after the given timout period and put the CPU to sleep with the following calls:
    __WFE();

    __SEV();

    __WFE();.  

Children
Related