A feature complete driver for the MAX17048 lithium fuel gauge from Maxim.
Dependents: MAX17048_HelloWorld ECGAFE_copy MAX17048_HelloWorld Orion_newPCB_test_LV ... more
Now fully tested!
Revision 3:32087cca331f, committed 2013-08-28
- Comitter:
- neilt6
- Date:
- Wed Aug 28 17:53:53 2013 +0000
- Parent:
- 2:0a98e081b48c
- Child:
- 4:e61b2723d2cf
- Commit message:
- Added open() method to probe for devices and load the default RCOMP value
Changed in this revision
MAX17048.cpp | Show annotated file Show diff for this revision Revisions of this file |
MAX17048.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MAX17048.cpp Wed Aug 14 04:52:16 2013 +0000 +++ b/MAX17048.cpp Wed Aug 28 17:53:53 2013 +0000 @@ -15,13 +15,27 @@ */ #include "MAX17048.h" -#include "mbed.h" MAX17048::MAX17048(PinName sda, PinName scl) : m_I2C(sda, scl) { //Nothing else to initialize } +bool MAX17048::open(void) +{ + //Probe for the MAX17048 using a Zero Length Transfer + if (!m_I2C.write(m_ADDR, NULL, 0)) { + //Load the default RCOMP value + writeRCOMP(m_RCOMP0); + + //Return success + return true; + } else { + //Return failure + return false; + } +} + void MAX17048::reset(void) { //Write the POR command
--- a/MAX17048.h Wed Aug 14 04:52:16 2013 +0000 +++ b/MAX17048.h Wed Aug 28 17:53:53 2013 +0000 @@ -29,16 +29,24 @@ * * MAX17048 gauge(p28, p27); * - * int main() { - * while (1) { - * //Read the cell voltage - * float vcell = gauge.vcell(); + * int main() + * { + * //Try to open the MAX17048 + * if (gauge.open()) { + * printf("Device detected!\n"); * - * //Print the cell voltage - * printf("Vcell = %f\n", vcell); + * while (1) { + * //Read the cell voltage + * float vcell = gauge.vcell(); * - * //Sleep for 0.5 seconds - * wait(0.5); + * //Print the cell voltage + * printf("Vcell = %f\n", vcell); + * + * //Sleep for 0.5 seconds + * wait(0.5); + * } + * } else { + * printf("Device not detected!\n"); * } * } * @endcode @@ -64,6 +72,14 @@ */ MAX17048(PinName sda, PinName scl); + /** Probe for the MAX17048 and load the default RCOMP value if present + * + * @returns + * 'true' if the device exists on the bus, + * 'false' if the device doesn't exist on the bus. + */ + bool open(void); + /** Command the MAX17048 to perform a power-on reset */ void reset(void);