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

Battery consumption using twi pheripheral

Hello,

I am using a custom board with nrf52382 chip and mma8652 accelerometer, This accelerometer has only i2c peripherals to communicate with. I am using twi_software and SDK 11 with s132v2.0 soft device to make the communication done.

bool I2CInit()
{       
 return(twi_master_init());
 }

 void I2CWriteReg(uint8_t device_addr, uint8_t reg_addr, uint8_t reg_val)
 {

value = I2CInit();
uint8_t data_buff[2];
data_buff[0] = reg_addr;
data_buff[1] = reg_val;
twi_master_transfer(device_addr, &data_buff[0], 2, true);
configure_SDA_SCL_for_output_pins();
    }

void I2CReadReg(uint8_t device_addr, uint8_t reg_addr, uint8_t *reg_val, uint8_t num_bytes)
{   

value = I2CInit();
/* First send register address */
twi_master_transfer((device_addr<<1), &reg_addr, 1, false);         /* do not send stop bit */
twi_master_transfer(((device_addr<<1)|0x01), reg_val, num_bytes, true);     /* complete transfer with stop bit */
configure_SDA_SCL_for_output_pins();
}

 void configure_SDA_SCL_for_output_pins() 
  {
    TWI_SDA_STANDARD0_NODRIVE1(); /*lint !e416 "Creation of out of bounds pointer" */
    TWI_SCL_STANDARD0_NODRIVE1(); /*lint !e416 "Creation of out of bounds pointer" */
    }

this is how I am using i2c read and write operations.

After the operation is over SCL and SDA pins are always High so that the communication with the accelerometer is inactive.

Do these High pins might be the cause of larger current consumption.Because clearing these pins manually is not helping it is leading accelerometer to do the last operation it was doing either reading or writing

From the specs of accelerometer in low power mode and with 50HZ sampling frequency current drawn is 20uA

Note: At this moment of time BLE is disconnected and other peripherals are being disconnected.

Apart from the accelerometer, I am using LED and pancake motor, PWM is used to drive these components, for LED PWM driver and for motor APP PWM, every known and mention cases in the forum about PWM is being handled and are also not active at the time of accelerometer working.

BLE sending and receiving of settings is drawing 4 - 6mA of current. which if in the case left active for a long time draws more current So advertisement is done only when the tap is detected by the accelerometer.

interrupt from the accelerometer is being handled by Gpiote driver.

  void acc_interrupt_pins_config() 
 {

ret_code_t err_code;

nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);     
in_config.pull = NRF_GPIO_PIN_PULLUP;                                           
err_code = nrf_drv_gpiote_in_init(ARDUINO_4_PIN, &in_config, acc_interrupt_handler);   
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(ARDUINO_4_PIN, true);
    }

Can you verify the code I am using for TWI peripheral and why it is drawing more current?

Related