2019-11-14 03:53 AM
Hi fiends, I have a problem with Sleep mode in my BlueNRG-1.
I want put core in sleep mode for a given time. I writed a function based on power management examples of BlueNRG-1 navigator SDK, this is:
void Sleep_ms(uint16_t time)
{
tBleStatus rets;
CKGEN_SOC->CLOCK_EN=0x0000C063; //NVM(mandatory) y GPIO
if (time==0) hci_reset();
if (!sleepflag) // Global flag to program ADV timer once by sleep mode entering
{
do{
BTLE_StackTick();
hci_le_set_scan_response_data(0,0);
rets = aci_gap_set_discoverable(ADV_NONCONN_IND, (time*1000)/625, (time*1000)/625, PUBLIC_ADDR, NO_WHITE_LIST_USE, sizeof(local_name), local_name, 0, 0, 0, 0);
}while (rets!=0);
sleepflag=1;
}
__disable_irq();
rets = BlueNRG_Sleep(SLEEPMODE_NOTIMER,0,0); // Sleep mode
__asm("nop");
CKGEN_SOC->CLOCK_EN=0x000F0067; // Activate SYSCTRL
__enable_irq();
}
Code programs advertising timers with the desired wakeup time. The cpu must wakeup after when BLE sleep timer expires and must continue executing the next instruction (a NOP in this case).
The problem seems, the BlueNRG_Sleep() doesn't enter in sleep mode, or it wakes up inmediately. In all cases, it returns SUCCESS.
Without STLINK conneted (no debugging), the cheking of the SysCtrl_GetWakeupResetReason(); returns RESET_BLE_POR.
With STLINK connected (debugging), it returns RESET_SYSREQ as expected and seems normal the debugger wakes up the core I guess.
Do Somebody knows why this doesn't work?
Thank you very much.
Roger
2019-11-14 12:22 PM
I found the answer. Just put BTLE_StackTick(); before BlueNRG_Sleep() call.
Thanks