Seeed-Studio / ArduinoCore-mbed

3 stars 6 forks source link

XIAO_BLE_Sense(mbed 2.9.1) battery voltage monitor analogRead(P0_31), analogRead(PIN_VBAT), green LED does not work #13

Closed msfujino closed 1 year ago

msfujino commented 1 year ago

XIAO_BLE_Sense has battery charging and battery voltage monitoring functions. I am trying to check these functions with “mbed 2.7.2” or "mbed 2.8.1". The charging function worked as expected, but “analogRead(P0_31)” to read the battery voltage did not work. To check, I tried other analog pins from A0 to A5, and “analogRead()” worked without any problem.

It seems that there is a problem in the macro “analogPinToPinName(P)” used in the “analogRead()” function. In the definition, “g_APinDescription” (digital pin description) is used instead of “g_AAnalogPinDescription” (analog pin description). /Arduino15/packages/Seeeduino/hardware/mbed/2.7.2/cores/arduino/wiring_analog.cpp : 89

I changed “g_APinDescription” to “g_AAnalogPinDescription” and now “analogRead(P0_31)” also works as expected.

Is this a bug or a specification?

See also the link below. https://forum.seeedstudio.com/t/xiao-ble-sense-mbed-2-7-2-battery-charge-and-voltage-monitor-analogread-p0-31-does-not-work/266438

msfujino commented 1 year ago

Today, mbed 2.9.0 was released, but for some reason this problem has not been resolved. Unfortunately, in order to read the battery voltage, I need to fix /Arduino15/packages/seeduino/hardware/mbed/2.9.0/cores/arduino/pinDefinitions.h : 22. `//#define analogPinToPinName(P) (P >= PINS_COUNT ? NC : P < A0 ? g_APinDescription[P+A0].name : g_APinDescription[P].name)

define analogPinToPinName(P) (P >= PINS_COUNT ? NC : P < A0 ? g_AAnalogPinDescription[P+A0].name : g_AAnalogPinDescription[P].name)`

msfujino commented 1 year ago

In mbed 2.9.0, the definition of PIN_VBAT has been changed from (32u) to (6u). A battery is connected to P0_31. Instead of analogRead(P0_31), analogRead(PIN_VBAT) does not work. In addition, serial monitor does not come up and IDE hangs.

msfujino commented 1 year ago

v2.9.1 has been released, but analogRead(P0_31) returns 0xFFFFFFFFFF and analogRead(PIN_VBAT) hangs the IDE. It is not usable at all.

EDIT v2.9.1 has been released. analogRead(PIN_VBAT) works, but analogRead(P0_31) returns "0xFFFFFFFFFFFF". If I try to flash the green LED, I lose the COM port. It is still not usable at all.

msfujino commented 1 year ago

By replacing "variant.cpp" and "pins_arduino.h" in v2.9.1 with my modified "variant.cpp" and "pins_arduino.h", analogRead(P0_31) and analogRead(PIN_VBAT) and green LED will work correctly. analogReadL_EDG.zip

misterf13 commented 1 year ago

Soooo, is anyone looking into this?

misterf13 commented 1 year ago

I tried the fix from @msfujino and it works great. Could this be merged at some point for future releases?

Maxwelltoo commented 1 year ago

bugfixed on v2.9.2