2

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

  • 1
    Unlikely to be related to your problem but `0xA5 << 24` invokes undefined behavior. Always `u` suffix your integer constants - `0xA5u << 24` is fine. – Lundin Feb 14 '22 at 10:14
  • Thanks for the info. I will change it in code, but as you guessed, unfortunately this does not solve my problem. – Traummaennlein Feb 14 '22 at 12:10

0 Answers0