1 Star 0 Fork 0

DFRobot/DFRobot_MAX17043

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DFRobot_MAX17043.cpp 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
Arya11111 提交于 2022-02-28 09:57 +08:00 . V1.0.0
/*!
* @file DFRobot_MAX17043.cpp
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [ouki.wang](ouki.wang@dfrobot.com)
* @version V1.0
* @date 2018-4-14
* @url https://github.com/DFRobot/DFRobot_MAX17043
*/
#include "DFRobot_MAX17043.h"
DFRobot_MAX17043::DFRobot_MAX17043() {}
int DFRobot_MAX17043::begin()
{
// write16(MAX17043_COMMAND, 0x0054); //power on reset
write16(MAX17043_COMMAND, 0x5400); //power on reset
delay(10);
_DBG_CODE(Serial.print("\nbegin: "));
_DBG_CODE(Serial.println(read16(MAX17043_CONFIG), HEX));
if(read16(MAX17043_CONFIG) == 0x971c) { //default 0x971c
write16(MAX17043_MODE, 0x4000); //quick start
write16(MAX17043_CONFIG, 0x9700);
_DBG_CODE(Serial.println(read16(MAX17043_CONFIG), HEX));
delay(10);
return 0;
}
return -1;
}
float DFRobot_MAX17043::readVoltage()
{
return (1.25f * (float)(read16(MAX17043_VCELL) >> 4));
}
float DFRobot_MAX17043::readPercentage()
{
uint16_t per = read16(MAX17043_SOC);
return (float)((per >> 8) + 0.003906f * (per & 0x00ff));
}
void DFRobot_MAX17043::setInterrupt(uint8_t per)
{
uint16_t temp;
if(per > 32)
temp = 32;
else if(per < 1)
temp = 1;
temp = 32 - temp;
writeRegBits(MAX17043_CONFIG, temp, 0x01f, 0);
}
void DFRobot_MAX17043::clearInterrupt()
{
writeRegBits(MAX17043_CONFIG, 0, 0x01, 5);
}
void DFRobot_MAX17043::setSleep()
{
writeRegBits(MAX17043_CONFIG, 1, 0x01, 7);
}
void DFRobot_MAX17043::setWakeUp()
{
writeRegBits(MAX17043_CONFIG, 0, 0x01, 7);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/dfrobot/DFRobot_MAX17043.git
git@gitee.com:dfrobot/DFRobot_MAX17043.git
dfrobot
DFRobot_MAX17043
DFRobot_MAX17043
master

搜索帮助