I’m running into a problem with the Artemis Nano where I want it to go into sleep mode when a pushbutton is pressed, then exit it as soon as the button is pressed again. the sleep and wakeup functions are within interrupts and are set to trigger on a falling edge. The problem is that as soon as the the interrupt gets attached, it immediately triggers to go into sleep mode, then hard-faults and starts blinking the LED in the S.O.S. pattern.
The relevant code is below, as is the output on my serial monitor
#define SLEEP_INTERRUPT 4
setup
{
pinMode(SLEEP_INTERRUPT, INPUT);
#ifdef DEBUG
Serial.print("About to attach interrupt");
#endif
attachInterrupt(digitalPinToInterrupt(SLEEP_INTERRUPT), sleepModeSwitch, FALLING);
#ifdef DEBUG
Serial.print("Interrupt attached");
#endif
}
void sleepModeSwitch()
{
#ifdef DEBUG
Serial.print("Interrupt triggered! button status: "); Serial.println(digitalRead(SLEEP_INTERRUPT));
#endif
if(sleep_mode_status == false)
{
goToSleep();
}
else
{
wakeUp();
}
}
void goToSleep()
{
sleep_mode_status = true;
#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);
// Stop the BLE advertising.
BLE.stopAdvertise() ;
powerControlADC(false);
for(int x = 0; x < 50; x++)
{
if(x != 18)
{
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_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 wakeUp()
{
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);
Serial.println("Waking up! Hello world!");
#endif
deepSleepTimer = millis() ;
sleep_mode_status = false;
}
DATARX 055 INITIAL TEST
About to attach interrupt
Interrupt triggered! button status: 1
Going to sleep
++ MbedOS Error Info ++
Error Status: 0x80FF0144 Code: 324 Module: 255
Error Message: Assertion failed: status == osOK
Location: 0x29FED
File: mbed-os/rtos/source/ThisThread.cpp+225
Error Value: 0x0
Current Thread: main Id: 0x10006E2C Entry: 0x2B141 StackSize: 0x1000 StackMem: 0x10005E08 SP: 0x1005FED4
For more info, visit: https://mbed.com/s/error?error=0x80FF01 … TEMIS_NANO
– MbedOS Error Info –
Attached to the relevant pin is a basic RC debounce circuit, seen below:
I’m still testing, but I wanted to get some thoughts on what was happening here. According my multimeter and oscilloscope, the signal isn’t oscillating so I don’t know what could be generating the falling edge that should be needed to trigger the interrupt. Any thoughts on what might be happening?