|
本帖最后由 bennyrfid 于 2019-3-26 17:15 编辑
主芯片 51822
1:代码中 单独使用 app_button ,一切正常,按键 可以进入 app_button的事件处理函数 button_event_handler
2: 加入 看门狗代码,之后 app_button 事件无法进入 button_event_handler
请问 哪位大神指点指点,这是什么原因,如何解决,谢谢
相关代码如下:
static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
if (button_action == APP_BUTTON_RELEASE)
{
switch (pin_no)
{
case HLJC:
break;
case ZDJC:
break;
case XNLOCK:
break;
default:
Datasend("其他开关闭合",12,0);
break;
}
}
else if (button_action ==APP_BUTTON_PUSH )
{
switch (pin_no)
{
case PW_CHK://打开
break;
default:
Datasend("其他开关打开",12,0);
break;
}
}
}
static void buttons_init(void)
{
uint32_t err_code;
// Note: Array must be static because a pointer to it will be saved in the Button handler module.
static app_button_cfg_t buttons[] =
{
{HLJC, true, BUTTON_PULL, button_event_handler},
{XNLOCK, true, BUTTON_PULL, button_event_handler},
{ZDJC, true, BUTTON_PULL, button_event_handler},
{PW_CHK, true, BUTTON_PULL, button_event_handler}
};
APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, true);
err_code = app_button_enable();
APP_ERROR_CHECK(err_code);
}
void WDT_init(uint8_t time)
{
// Make sure peripherals are enabled (PAN v1.1, anomaly #23)
*(uint32_t *)0x40000504 = 0xC007FF9F;
// NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Synth << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
{
}
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_WDT->CONFIG = (WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);
NRF_WDT->CRV = 32768*time-1;
NRF_WDT->RREN = WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos;
NRF_WDT->TASKS_START = 1;
NRF_WDT->RR[0] = 0x6E524635;
}
主函数 main()
{
// Initialize
leds_init();
timers_init();
gpiote_init();
WDT_init(7); //只要加了这句 看门狗初始化 button_event_handler 就 无法进入
buttons_init();
ble_stack_init();
scheduler_init();
app_storage_init();
gap_params_init();
services_init();
advertising_init();
conn_params_init();
sec_params_init();
.................
}
|
|