Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
136
Ver.1.0.0
analog_write(DEEP_ANA_REG2, BATTERY_VOL_LOW);
cpu_sleep_wakeup(
PM_SLeepMode_Deep
,
PM_WAKEUP_PAD
, 0);
}
For “5316_ble_remote”, after shutdown at low battery, MCU enters deepsleep which
supports key press wakeup.
At the moment of wakeup by key press, SDK will perform one fast battery detect in user
initialization (function user_init) rather than in main_loop, so as to avoid errors as shown
below.
Given that LED blinking has been issued for low battery, MCU entered deepsleep, but
wakes up from deepsleep by key press. If processed in main_loop, battery detect needs
to wait 500ms at least to be executed ; during this duration Slave could have sent many
advertising packets, and may even connect with master, which will lead to a bug that
device resumes working after low battery alarm.
For this reason, battery detect is performed at user initialization instead. So battery detect
is added in user initialization:
if
(analog_read(DEEP_ANA_REG2) == BATTERY_VOL_LOW){
battery_power_check(BATTERY_V 200);
//2.2V
}
else
{
battery_power_check(BATTERY_VOL_MIN);
//2.0 V
}
Please note that the initialization of GPIO wakeup must be placed before the code above
or it may lead to GPIO wakeup failure.
Value of the analog register “DEEP_ANA_REG2” can tell whether it’s wakeup from low
battery shutdown. Battery detect after this wakeup will raise 2000mV alarm voltage to
2200mV recover voltage, based on the reason below:
Tolerance in battery detect makes it difficult to ensure consistent result on every
measurement. Given 20mV error, for first time, 1990mV might trigger MCU to shutdown;
however, after wakeup, at user initialization it could be measured at 2005mV, so 2000mV
alarm voltage would lead to the bug above.
Considering this, at battery detect after wakeup from shutdown, alarm voltage is raised
by a value slightly higher than maximum tolerance of low battery detect.
Since the example 2200mV recover voltage only occurs after voltage lower than 2000mV
is detected to shutdown MCU, user does not need to worry that applications would give
low voltage alarm when actual voltage is 2.0~2.2V. End user should recharge or replace
battery at low battery alarm to ensure normal product performance.