BelaPlatform / Bela

Bela: core code, IDE and lots of fun!
Other
495 stars 139 forks source link

Detect whether we are being powered externally or not #552

Open giuliomoro opened 5 years ago

giuliomoro commented 5 years ago

Particularly useful for Salt.

https://forum.bela.io/d/872-output-when-patch-when-not-running/34

giuliomoro commented 5 years ago

This can be done by looking at register Status Register (STATUS) (Address = 0x0A) .

Bit 2 will be high when there is power on the USB_VIN line, and Bit 3 will be high when there is power on the AC_VIN line. Quick and dirty check:

i2cget -y -f 0 0x24 0xa

You would normally read:

both: 0x8c usb only: 0x84 ac only: 0x88

In the case of Salt, these correspond to:

both: 0x8c (Eurorack power + USB connected to host. All good) usb only: 0x84 (No Eurorack power >>> should fail/warn the user!!!) ac only: 0x88 (No USB power. All good)

Datasheet: http://www.ti.com/lit/ds/symlink/tps65217.pdf