I do have an ATSAM4N and try to go to backup mode as soon as the external power is turned off to keep the RTC time running. Therefore, a battery is added to support VDDIO.
I manage to get the SAM4N in backup mode by activating the supply monitor interupt and
#define SUPC_SMMR_SMTH (11 << 0)
#define SUPC_SMMR_SMSMPL (1 << 8)
#define SUPC_SMMR_SIMEN (1 << 13)
#define SUPC_CR_VROFF (1 << 2)
#define SUPC_CR_KEY (0xA5 << 24)
int main()
{
//...
SUPC->SUPC_SMMR = SUPC_SMMR_SMTH | SUPC_SMMR_SMSMPL | SUPC_SMMR_SIMEN;
//...
}
void SUPC_IRQHandler()
{
SUPC->SUPC_CR = SUPC_CR_VROFF | SUPC_CR_KEY;
}
I figured that this works, because when I cut power, the VDDCORE drops to zero (which is not the case if I comment the line in interrupt).
I thought that waking up the SAM4N by supply monitor would be easy. Just set the registers right.
#define SUPC_WUMR_SMEN (1 << 0)
int main()
{
//...
SUPC->SUPC_WUMR = SUPC_WUMR_SMEN;
//...
}
But when I apply power again, nothing happens. What did I forget to get the SAM4N restarted again?
Thanks