Detect the reason for the reset

Hello,
I need to detect it (mainly separate the reset with the button from the rest), but it doesn’t work, I always have 0 in u32Reset_reason. Maybe this register is already read elsewhere in the library?

In DeepSleep Lorawan example:

void setup(void)
{
u32Reset_reason = NRF_POWER->RESETREAS;
NRF_POWER->RESETREAS = 0xFFFFFFFF; //Clear reset reason register

(… SERIAL INIT …)

API_LOG("RESET", "reason  0x%08x.\n ",u32Reset_reason);

If you are using PlatformIO:

Just use the BSP function to get the reset reason:

uint32_t u32Reset_reason = readResetReason();
Serial.printf("Reset Reason = %ld %08x\n", u32Reset_reason, u32Reset_reason);

Works for me. First is after flashing the device, second after pushing reset button

09:51:07.716 --> =====================================
09:51:07.716 --> RAK4631 LoRaWan Deep Sleep Test
09:51:07.716 --> =====================================
09:51:07.716 --> Reset Reason = 4 00000004
09:51:07.826 --> Start network join request
09:51:08.215 --> LoRaWan init success
09:52:20.003 --> =====================================
09:52:20.003 --> RAK4631 LoRaWan Deep Sleep Test
09:52:20.003 --> =====================================
09:52:20.003 --> Reset Reason = 1 00000001
09:52:20.112 --> Start network join request
09:52:20.503 --> LoRaWan init success

If you are using Arduino IDE with the RAK BSP, it is not implemented.

Hi @beegee , thanks for pointing me.
I use Arduino ,found in file C:\Users\admin\AppData\Local\Arduino15\packages\rakwireless\hardware\nrf52\1.0.1\cores\nRF5\wiring.h

void init( void )
{
  // clear reset reason: can save it for application usage if needed.
  NRF_POWER->RESETREAS |= NRF_POWER->RESETREAS;

just add there

    _reset_reason = NRF_POWER->RESETREAS;
 // clear reset reason: can save it for application usage if needed.
  NRF_POWER->RESETREAS |= NRF_POWER->RESETREAS;

and

uint32_t readResetReason(void)
{
  return _reset_reason;
}

in wiring.h

uint32_t readResetReason(void); 

And now it works :).

PS. This is already in BSP 1.2.0

We will integrate this in the next BSP update.

Hello @beegee,
have one more problem in this topic, thought I have just failure in base board/module, so ordered all types of base you offer and also new RAK4631, the result is the same.
So the issue is: module doesn’t restart when I press reset button, same when I just short RESET pin to GND. When I keep pressed reset button program just run normally.
I build my app on the top of DeepSleep LoraWan.

Hello @zolax
Both the reset button and the reset pin on the RAK19001 are hardware wired to the reset pin of the nRF52 MCU. Your problem sounds very strange to me and I have no explanation for it. It is not possible to disable a reset by software.

I have many RAK4631 and all kinds of Base Boards here and I never experienced what you are describing here.

The reset button is sometimes difficult to push, specially if you have thick fingers like me, but connecting the RESET pin to GND should always work.

I didn’t use the deepsleep example for a long time, just for testing, can you try one of our other examples.

Hi @beegee ,
thanks for the answer. Now I upload Read_Battery_Level, the same - it just doesn’t give a sh*t and doesn’t reset ;). I used now RAK4631 RUI but I program the firmware using nrf52840-DK.
In couple days I will recive my custom board for RAK4630 so will be able to test one more module.

Here is the video: https://youtu.be/wXiH5USNVQY

Problem was bad SoftDevice (I should use WisCore_RAK4631_Board_Bootloader.hex).

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.