Program to demonstrate how to configure the PMIC on the MAX32620HSP (MAXREFDES100#)
Fork of HSP_PMIC_Demo by
main.cpp@17:9a467f9a0579, 2016-10-06 (annotated)
- Committer:
- switches
- Date:
- Thu Oct 06 17:11:37 2016 +0000
- Revision:
- 17:9a467f9a0579
- Parent:
- 14:4c4094890fde
- Child:
- 18:b64938c813dc
Added comments to explain the code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan | 0:7dec7e9ac085 | 1 | #include "mbed.h" |
switches | 14:4c4094890fde | 2 | #include "MAX14720.h" |
switches | 14:4c4094890fde | 3 | |
switches | 14:4c4094890fde | 4 | // I2C Master 2 |
switches | 14:4c4094890fde | 5 | I2C i2c2(I2C2_SDA, I2C2_SCL); |
dan | 0:7dec7e9ac085 | 6 | |
switches | 14:4c4094890fde | 7 | #define I2C_ADDR_PMIC (0x54) |
switches | 14:4c4094890fde | 8 | MAX14720 max14720(&i2c2,I2C_ADDR_PMIC); |
switches | 14:4c4094890fde | 9 | |
switches | 14:4c4094890fde | 10 | DigitalOut led(LED1); |
switches | 14:4c4094890fde | 11 | InterruptIn button(SW1); |
switches | 14:4c4094890fde | 12 | |
switches | 14:4c4094890fde | 13 | void turnOff() |
switches | 14:4c4094890fde | 14 | { |
switches | 17:9a467f9a0579 | 15 | // Write the power down command to the PMIC |
switches | 14:4c4094890fde | 16 | max14720.shutdown(); |
switches | 14:4c4094890fde | 17 | } |
dan | 0:7dec7e9ac085 | 18 | |
switches | 14:4c4094890fde | 19 | int main() |
switches | 14:4c4094890fde | 20 | { |
switches | 14:4c4094890fde | 21 | int result; |
switches | 17:9a467f9a0579 | 22 | |
switches | 17:9a467f9a0579 | 23 | // Assign turnOff function to falling edge of button |
switches | 14:4c4094890fde | 24 | button.fall(&turnOff); |
switches | 17:9a467f9a0579 | 25 | |
switches | 17:9a467f9a0579 | 26 | // Turn LED signal on to make buck-boost output visible |
switches | 14:4c4094890fde | 27 | led = 0; |
switches | 17:9a467f9a0579 | 28 | |
switches | 17:9a467f9a0579 | 29 | // Override the default value of boostEn to BOOST_ENABLED |
switches | 14:4c4094890fde | 30 | max14720.boostEn = MAX14720::BOOST_ENABLED; |
switches | 17:9a467f9a0579 | 31 | // Note that writing the local value does directly affect the part |
switches | 17:9a467f9a0579 | 32 | // The buck-boost regulator will remain off until init is called |
switches | 17:9a467f9a0579 | 33 | |
switches | 17:9a467f9a0579 | 34 | // Call init to apply all settings to the PMIC |
switches | 14:4c4094890fde | 35 | result = max14720.init(); |
switches | 14:4c4094890fde | 36 | if (result == MAX14720_ERROR) printf("Error initializing MAX14720"); |
switches | 17:9a467f9a0579 | 37 | |
switches | 17:9a467f9a0579 | 38 | // Wait 1 second to see the buck-boost regulator turn on |
switches | 14:4c4094890fde | 39 | wait(1); |
switches | 17:9a467f9a0579 | 40 | |
dan | 0:7dec7e9ac085 | 41 | while(1) { |
switches | 17:9a467f9a0579 | 42 | // Turn off the buck-boost regulators |
switches | 14:4c4094890fde | 43 | max14720.boostSetMode(MAX14720::BOOST_DISABLED); |
switches | 17:9a467f9a0579 | 44 | wait(0.5); |
switches | 17:9a467f9a0579 | 45 | |
switches | 17:9a467f9a0579 | 46 | // Change the voltage of the buck-boost regulator and enable it |
switches | 17:9a467f9a0579 | 47 | max14720.boostSetVoltage(2500); |
switches | 17:9a467f9a0579 | 48 | max14720.boostSetMode(MAX14720::BOOST_ENABLED); |
switches | 14:4c4094890fde | 49 | wait(0.5); |
switches | 17:9a467f9a0579 | 50 | |
switches | 17:9a467f9a0579 | 51 | // Change the voltage of the buck-boost regulator |
switches | 17:9a467f9a0579 | 52 | // Note that the MAX14720 cannot change the buck-boost voltage while |
switches | 17:9a467f9a0579 | 53 | // it is enabled so if boostEn is set to BOOST_ENABLED, this |
switches | 17:9a467f9a0579 | 54 | // function will disable it, change the voltage, and re-enable it. |
switches | 14:4c4094890fde | 55 | max14720.boostSetVoltage(5000); |
switches | 14:4c4094890fde | 56 | wait(0.5); |
stevep | 4:81cea7a352b0 | 57 | } |
dan | 0:7dec7e9ac085 | 58 | } |