Login Register
ZigBee SDK - voltage_detect()
Jul 15, 2022 07:20




In the ZigBee SDK manual there is the following description for Voltage Detect:

3.2.10 Voltage detection
In order to prevent abnormal operation of low-voltage systems, the SDK provides a voltage detection function
based on the ADC driver implementation, which requires below attention.

1) It needs to use the I/O port that supports ADC function, and the I/O port used for ADC detection cannot
be used for other functions.

2) When using DRV_ADC_VBAT_MODE mode, the I/O port needs to be floating.

3) When using DRV_ADC_BASE_MODE mode, the I/O port needs to be connected to a voltage test point.

• Initialization

void voltage_detect_init(void)

• Voltage detection


But where do you define the pin used for voltage detection and the mode?

In the drv_hw.c there is the following definition of the function voltage_detect_init():

static void voltage_detect_init(void)



#if defined(MCU_CORE_826x)

drv_adc_mode_pin_set(DRV_ADC_VBAT_MODE, NOINPUT);

#elif defined(MCU_CORE_8258) || defined(MCU_CORE_8278)

drv_adc_mode_pin_set(DRV_ADC_VBAT_MODE, GPIO_PC5);

#elif defined(MCU_CORE_B91)

drv_adc_mode_pin_set(DRV_ADC_BASE_MODE, ADC_GPIO_PB0);




Should I change the pin and the mode in this function?

I don't think this is the best idea. If I have, for example, two projects that use different pin for voltage detection, I would have to remember to change it, each time I work on a different project.

2 replies
TL_Soyo Jul 15, 2022 10:35


   you need manage ADC pin by yoursef,it is a demo for user.

wes58 [Author] Jul 15, 2022 11:15

Hi Soyo,

How can it be a demo, if the function voltage_detect_init() is defined in the drv_hw.c, which is used by all projects.

The function voltage_detect_init() is called by drv_platform_init(), which is located also in the drv_hw.c file. I can modify this file, but this is not the correct way of doing this - I think! Changing it for one project will affect all projects.

I can modify the voltage_detect_init() function like this:

static void voltage_detect_init(void)
// drv_adc_mode_pin_set(DRV_ADC_VBAT_MODE, GPIO_PC5);
   drv_adc_mode_pin_set(VOLT_DETECT_MODE, VOLT_DETECT_PIN);

And define in app_cfg.h (or board header file) the following:



But, when there is an upgrade to the SDK I will have to remember to do it again.

That's why, I think, something like this should be implemented in the SDK. That's when users can manage the ADC pin for voltage detection.