Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 11 months ago.
MAX17043 I2C communication
Hello, Do You have an experience with IC MAX17043 ? It is a battery fuel gauges and I try to communicate with its through I2C. I have wrote a simple code by using library MAX17043 but it does not work correct. It returns incorrect values such as below.
MAX17043
#include "mbed.h" #include "USBSerial.h" #include "MODSERIAL.h" #include "MAX17043.h" DigitalOut LedStatus(P0_13); DigitalOut LedBattery(P0_14); MAX17043 battery(P0_5, P0_4, 36); USBSerial usb; MODSERIAL uart(P0_19, P0_18); InterruptIn timepulse(P0_17); void rxCallback(MODSERIAL_IRQ_INFO *q) { LedBattery = !LedBattery; usb.putc(uart.getc()); } void toogle(){ LedStatus = !LedStatus; } int main(){ battery.selfInit(); battery.reset(); timepulse.rise(&toogle); uart.baud(9600); // uart.attach(&txCallback, MODSERIAL::TxIrq); // uart.attach(&rxCallback, MODSERIAL::RxIrq); // uart.attach(&txEmpty, MODSERIAL::TxEmpty); while(1){ wait(1); float volt = battery.getFloatVCell(true); float soc = battery.getSOC(true); usb.printf("SOC: %f\r\n", soc); usb.printf("Voltage: %f\r\n", volt); } }
1 Answer
7 years, 11 months ago.
It really doesnt make sence just to publish the main module. If you want to to look into it, you have to see en the libery
If you like the soc value en %, you have to ude thes floatsoc funktion or divide the result with 256
Hello, okay, here is link for modules. It is made by Mark Gottscho. I found any problem in those modules.
https://developer.mbed.org/users/mgottscho/code/SensorsLib/
posted by 19 Dec 2016Hello, I tried code below with the same result. It does not work correct. I think connection of MAX17043 is ok because i tried I2C scanner and it came back address 0x36.
code
#include "mbed.h" #include "USBSerial.h" #include "MODSERIAL.h" #include "MAX17043.h" const int address = 0x36; //#define vcell (0x02) //#define command (0xFE) //#define command_reset (0x5400) //#define quick_start (0x4000) //#define soc (0x04) DigitalOut LedStatus(P0_13); DigitalOut LedBattery(P0_14); I2C battery_manager(P0_5, P0_4); USBSerial usb; MODSERIAL uart(P0_19, P0_18); InterruptIn timepulse(P0_17); void rxCallback(MODSERIAL_IRQ_INFO *q) { LedBattery = !LedBattery; usb.putc(uart.getc()); } void toogle(){ LedStatus = !LedStatus; } int main(){ char data_read[2]; char cmd[2]; battery_manager.frequency(400000); cmd[0] = 0x00; cmd[1] = 0x54; battery_manager.write(address, cmd, 2); cmd[0] = 0x4000; battery_manager.write(address, cmd, 1); timepulse.rise(&toogle); uart.baud(9600); while(1){ wait_ms(1000); cmd[0] = 0x04; battery_manager.write(address, cmd, 1, true); battery_manager.read(address, data_read, 2, true); usb.printf("soc1 %d\r\n", data_read[0]); usb.printf("soc2 %d\r\n", data_read[1]); } }