Closed khoa21214475 closed 8 months ago
Change to the following code to test, clearly indicating which pin I2C SDA, SCL is connected to. And check if the ID is 0x03
#define XPOWERS_CHIP_AXP2101
#include <Wire.h>
#include <Arduino.h>
#include "XPowersLib.h"
XPowersPMU PMU;
const uint8_t i2c_sda = You Board SDA;
const uint8_t i2c_scl = You Board SCL;
void setup()
{
Serial.begin(115200);
//Wire.begin() ; Don't use Wire.begin()unless you are sure you are selecting the correct i2c pin
bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl);
delay(100);
Serial.printf("getID:0x%x\n", PMU.getChipID());
if (result == false) {
Serial.println("PMU is not online..."); while (1)delay(50);
}
}
void loop(){
}
Dear lewisxhe,
Im tested, but the result is 0xFF
Can you search for the device with 0X34 and get the ID as 0XFF? Which board are you using? Did you buy the chip yourself?
Thanks Lewisxhe, I will try to find out this problem by your way! I use STM32L432 chip, I bought AXP2101 via taobao.com (link: https://item.taobao.com/item.htm?spm=a21n57.1.0.0.3682523cCuZCAO&id=730904931624&ns=1&abbucket=8#detail) Many thank Lewisxhe!
I read register at address 0x03 and the result is 0x4A. May be this library can not use for STM32 duino. My code:
const int deviceAddress = 0x34; // Địa chỉ của thiết bị I2C (thay thế bằng địa chỉ thực tế) void setup() { Serial.begin(115200); Wire.begin(); } void loop() { // Địa chỉ thanh ghi bạn muốn đọc int registerAddress = 0x03; // Thay thế bằng địa chỉ thanh ghi thực tế
// Bắt đầu gửi yêu cầu đến thiết bị Wire.beginTransmission(deviceAddress); Wire.write(registerAddress); Wire.endTransmission();
// Đọc 1 byte từ thiết bị Wire.requestFrom(deviceAddress, 1); if (Wire.available()) { int data = Wire.read(); // Đọc dữ liệu từ thanh ghi Serial.print("register 0x"); Serial.print(registerAddress, HEX); Serial.print(": 0x"); Serial.println(data,HEX); }
delay(1000); // Chờ 1 giây trước khi đọc lại }
Okay, I passed the test using Nucleo f411re
Really thank you very much. Your new update is running fine with STM32. I sincerely thank you very much!
Your new update is running fine with STM32.
If you are happy with the fix made by Lewis - why don't you close this ticket ?
Dear lewisxhe, when I scan i2c address, I received 0x34. but when I use example AXP2101_Voltage_Example, I received "PMU is not online" I don't know why, i2c bus is ok, 2 resistors pullup is ok, but my device can't connect to AXP2101! ////////////////////////////////////////////////////////////////////////////////////////////////////////////// Here is my code: