Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
133
Ver.1.0.0
To use PA7 as GPIO input channel, PA7 should act as general GPIO, and at initialization
user should follow its default configurations (ie, oe, output) without the need of special
modification.
#define
GPIO_VBAT_DETECT
GPIO_PA7
#define
PA7_FUNC
AS_GPIO
PA7 should output high level at ADC sampling.
gpio_set_input_en(GPIO_VBAT_DETECT, 0); //disable input function
gpio_set_output_en(GPIO_VBAT_DETECT, 1);//enable output function
gpio_write(GPIO_VBAT_DETECT, 1); //output 1
Generally, after ADC sampling, PA7 output can be disabled. However, for the
“5316_ble_remote”, PA7 on the corresponding HW is floating (NC), high-level output
won’t bring any current leakage, PA7 output is not disabled actually.
5.2.1.2 MUST Use ADC Differential Mode
Though in theory TLSR8232 ADC input supports both Single Ended Mode and
Differential Mode, in the SDK as well as actual applications, only Differential Mode is
allowed, and Single Ended Mode is forbidden.
Differential mode supports positive and negative input channel, thus voltage to be
measured equals the voltage difference of positive end and negative end.
If only one GPIO input channel is available for ADC, this GPIO should be set as positive
input channel, while GND should be set as negative input channel. By this setting,
voltage difference equals voltage of positive end.
The code for Low Battery Detect in the SDK is as below. API
“adc_set_all_differential_p_n_ain” selects PA7 as positive input channel, and GND as
negative input channel.
For “adc_set_all_differential_p_n_ain(ADC_MISC_CHN, gpio_no, GND)”, please see
SDK for code.
5.2.1.3 MUST Use DFIFO for ADC Sampling Valu
For Telink 826x family, ADC result is readable via related register. For TLSR8232, DFIFO
mode is used instead to get ADC result. Please refer to the following function in driver.
unsigned
int
adc_set_sample_and_get_result
(
void
)
;
5.2.2 Dedicated Low Battery Detect Demo
In the project “5316_ble_remote” of the “app_config.h” file, set the macro
“BATT_CHECK_ENABLE” to 1, ADC is dedicated for Low Battery Detect. Users can also
refer to the project “5316_ble_remote” for Low Battery Detect demo.