Hello, I have a project using an ATSAME70-N19A where I need to detect power loss so that I can call the appropriate functions to go into backup mode.
The circuit has a lithium coin cell that is little below 3V and the basic idea is to use the supply controller to detect the 3.3V supply fading, and then to call the SUPC_Handler() function.
Following the documentation, I have set a threshold at 3 V on the SUPC, enabled the interrupt, and configured the SUPC for continuous monitoring.
This is the code I use for configuring the SUPC:
//enable continuous measuring
supc_enable_monitor_reset(SUPC); //Enable reset on SUPC detection
supc_set_monitor_threshold(SUPC, 5); //see page 2045
supc_backup_sram_off(SUPC); //Disable backup SRAM
supc_enable_monitor_interrupt(SUPC); //Enable SUPC interrupt
SUPC->SUPC_WUMR |= (1<<1); //Enable SUPC wakeup
SUPC->SUPC_WUMR |= (1<<6); //Enable WKUP1 for tamper events
SUPC->SUPC_SMMR |= (1<<8); //Enable continuous monitoring
//read the SMS register to clear flags (make sure interrupts are ready)
U32 tmp = SUPC->SUPC_SR;
NVIC_DisableIRQ(SUPC_IRQn);
NVIC_ClearPendingIRQ(SUPC_IRQn);
NVIC_SetPriority(SUPC_IRQn, 0);
NVIC_EnableIRQ(SUPC_IRQn);
In a perfect world, the SUPC would then call the handler below when the power is pulled:
void SUPC_Handler(void)
{
//if we get here, power is pulled, goto sleep
enterBackUpMode();
}
However, I have the following evidence to suggest it is not being called. After pulling the power I made the following observations
1.) The function I call from the handler disables the internal regulator, however, I still see 1.2 V coming from the core regulator on my board.
2.) The chip draws about 5 mA from the battery, It appears to be in some kind of sleep. But certainly not backup mode.
*it should be noted the function "enterBackUpMode()" is tested and works fine
The circuit I have strongly resembled the reference circuit in the datasheet, and it is possible that I have 1 mA of reverse current leakage back to the regulator. but certainly not 5!
So my single most pressing question is how do get the SUPC_Handler() function to trigger!
any help is appreciated greatly!