Author Topic: I2C using too much current  (Read 948 times)

robogeek78

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
I2C using too much current
« on: December 24, 2015, 01:38:52 PM »
I am making a custom design and I am using i2c.

The problem i am having is when I turn on i2c it uses current in ulp Mode. I properly get 4 µA but when i do nothing else but initalize the i2c with:
Code: [Select]
Wire.beginOnPins(PIN_SCL, PIN_SDA); It increases the ulp mode current to 1343 µA total. This is unacceptable for my design and I would like to know what i can do to the Wire initialization routine to help with this or create a disconnect pin routine to "Wire.End()" the i2c and reinitialize on wake.

I have 10k pullups. I have tried disabling the internal pullups in wire.cpp. Both SCL and SDA are high and not drawing current. All else with the circuit is the same.

Anyone have any insight?

robogeek78

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: I2C using too much current
« Reply #1 on: December 26, 2015, 08:58:32 AM »
ok i have done some research into this and have some more information.

the twi_master_init function at
Code: [Select]
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos; is where the device starts drawing the additional ~1.3mA of current.

I have tried to disable it after it is enabled but it won't go back to the original current draw after it has been enabled.

I am going to move forward with coding the rest of my project but I believe my solution, unless someone else has any suggestions, will be to utilize a software based i2c master this will avoid the weird hardware peripheral getting locked in an enabled state.

Thanks for reading.

Gorm Aaen

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: I2C using too much current
« Reply #2 on: January 21, 2016, 04:45:30 AM »
Hi robogeek78,

I got the same issue with IC2 and I fixed it by adding the TWI disable before going to ULP and doing the TWI enable when waking up.

I did it by adding two functions to the RFDuino version of the Wire lib. (wire.cpp and wire.h):

void TwoWire::awake(void) {
   
   *(uint32_t *)((uint32_t)twi + 0xFFC) = 1;
   twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
   delayMicroseconds(10);
   
}

void TwoWire::sleep(void) {
   
   twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
    *(uint32_t *)((uint32_t)twi + 0xFFC) = 0;
   delayMicroseconds(10);
   
}

(remember to update the wire.h header with the two new functions)

...and now you can add in you Sketch:
....
   Wire.sleep();
   RFduino_ULPDelay(INFINITE);
   Wire.awake();
...

Hope this helps.

Cheers