- Mon Oct 23, 2023 11:35 am
#244762
I've been working on a device using the Artemis Nano that can be put to sleep and woken up with a pushbutton. I'm now adding BLE to the mix to broadcast data and such. The problem I'm running into now is that once the device has been put to sleep and wakes up again, I can't get it to connect to BLE. It connects to nRF connect just fine prior to going to sleep, but can't connect to it afterwards.
Code: Select all
Is there something being disabled by the sleep mode that I haven't re-enabled in the wakeup? I tried running BLE.end() after BLE.stopAdvertise() (to put to sleep) then running BLE.begin() before BLE.advertise() (while waking up), and that got me a hardfault, so chances are I just did it wrong, but I'm not quite sure how.void sleepModeSwitch()
{
if (millis() - debounce < DEBOUNCETIME )
{
return;
}
if(sleep_mode_status == false)
{
debounce = millis();
sleep_mode_status = true;
}
else
{
wakeFromSleep();
debounce = millis();
sleep_mode_status = false;
}
}
void goToSleep()
{
if (millis() - debounce < DEBOUNCETIME )
{
return;
}
#ifdef DEBUG
Serial.println("Going to sleep");
delay(50); //Wait for serial to finish
Serial.end(); //Power down UART(s)
#endif
// turn off the led.
digitalWrite(LED_BUILTIN, LOW);
//digitalWrite(BATTERY_LED, HIGH);
// Stop the BLE advertising.
BLE.stopAdvertise() ;
powerControlADC(false);
for(int x = 0; x < 50; x++)
{
if(x != SLEEP_INTERRUPT && x != BATTERY_LED)
{
//am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE);
}
}
//Power down Flash, SRAM, cache
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_CACHE); //Turn off CACHE
am_hal_pwrctrl_memory_deepsleep_retain(AM_HAL_PWRCTRL_MEM_SRAM_384K); // Retain all SRAM (0.6 uA)
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_FLASH_512K); //Turn off everything but lower 512k
//am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_SRAM_64K_DTCM); //Turn off everything but lower 64k
//am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); //Turn off all memory (doesn't recover)
// // Enable interrupts to the core.
am_hal_interrupt_master_enable();
// //Enable the timer interrupt in the NVIC.
// NVIC_EnableIRQ(STIMER_CMPR6_IRQn);
//Go to Deep Sleep.
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP);
}
void wakeFromSleep()
{
am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_MAX);
// Renable UART0 pins
am_hal_gpio_pinconfig(48, g_AM_BSP_GPIO_COM_UART_TX);
am_hal_gpio_pinconfig(49, g_AM_BSP_GPIO_COM_UART_RX);
am_hal_pwrctrl_periph_enable(AM_HAL_PWRCTRL_PERIPH_UART0);
initializeADC();
#ifdef DEBUG
Serial.begin(115200);
delay(10);
Serial.println("Waking up! Hello world!");
#endif
BLE.advertise();
deepSleepTimer = millis() ;
sleep_mode_status = false;
//digitalWrite(BATTERY_LED, LOW);
//digitalWrite(LED_BUILTIN, HIGH);
}