nRF52832 DK sleep stand-by power down

Okay so I understand that the question I am about to ask has been posted many times before however, the proposed solutions have not worked for me and hence I would like some assistance with this. I would like to start out by emphasizing that I am a senior firmware engineer. I have 12 years experience under my belt writing firmware for MCUs. Most if not all of my experience has been with the MSP430, MSP432, Atmel and Microchip MCUs. What I am trying to say is your response can be as technical as you want and I should be able to understand it.

My question is simple. I am trying to put my MCU to sleep. Unfortunately, I had had zero luck. The MCU/Board that I am using is the nRF52 Development Kit/nRF52832. Furthermore, the SDK that I am using is nRF Connect SDK. From my understanding, when it comes to Nordic chips we have the option of using either "nRF Connect SDK" IDE or Segger Embedded Studio IDEThe reason why I mention the SDK is because upon Googling "nRF52832 sleep", the search results seem to mention only Segger Embedded Studio examples and not "nRF Connect SDK" IDE. Furthermore, from my limited understanding, “nRF Connect SDK” is the wave of the future IDE for Nordic chips? Should I be using "nRF Connect SDK" IDE oover Segger Embedded Studio?

So in essence for me to start developing for the nRF52 DK, I had to install “nRF Connect for Desktop” which in turn installed “nRF Connect SDK” which in turn installed “Microsoft Visual Studio” which in turn installed "nRF Connect" plug-in. My understanding is that the "nRF Connect" allows you to use “Microsoft Visual Studio” to develop code for Nordic chips? The reason why I mention this is because by using "nRF Connect SDK" IDE, I am inherently using Zephyr, device tree, Kconfig, west, etc. However, when I Google Zephyr, I notice that it is a RTOS? 

The really beautiful thing about using Visual Studio with the “nRF Connect” plug-in is that it has a plethora of examples. Again, however, when I Google Zephyr, I notice that it is a RTOS. To me, it seems like all of the examples in Visual Studio with the “nRF Connect” plug-in are examples without the RTOS? In my opinion, ALL of the examples seem like a Super-Loop examples? What gives? Don’t get me wrong, I rather use super-loop rather than an RTOS, but that confuses me a little bit.

Okay all of that writing comes down to why I posted this question. I would love to know what instruction will put the nRF52 DK to sleep mode? Furthermore, I would like to write the code so that only a UART interrupt will wake up the nRF52 DK.  I already finished writing the UART code. It works flawlessly. That is the good news. The bad news is have not been able to put the nRF52 DK to sleep. It should be one instruction or one API function call? I tried at looking at all the example codes mentioned above but no luck. I also tried Google, however the only response I get are Segger Embedded Studio examples. I understand that the wave of the future is "nRF Connect SDK" however the examples and google do not reflect that. What am I doing wrong? Should I be using Segger Embedded Studio instead of "nRF Connect SDK"?

  • Hi Emilio, 

    Thanks for the very detailed information that you provided. 

    As you already noticed, the nRF Connect SDK (NCS) is the path forward. Those example you found for Segger Emebedded Studio , are mostly for nRF5 SDK which is our legacy SDK. 

    NCS has Zephyr as one of the main components. But Zephyr is not just an RTOS, but it's an RTOS ecosystem where you can find not only the core RTOS but also many libraries, protocol stacks, etc. 

    To get started it's strongly recommended to follow our nRF Connect SDK Academy course here: https://academy.nordicsemi.com/

    Regarding your question on how to put the nRF52 to sleep, I would suggest to take a look at the scheduling documentation here: https://docs.zephyrproject.org/latest/kernel/services/scheduling/index.html

    When there is no active thread (for example by calling k_sleep in the thread, or ask the thread to wait for a semaphore ) the RTOS will automatically put the MCU to sleep.

    You can find that in the blinky sample:


    You should see only a few uA current consumption in this example. 

    Multithreading and scheduling is covered in lesson 7 in the nRF Connect SDK Academy: https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-7-multithreaded-applications/

    Note that with UART sample, you would need to disable UART to achieve low current consumption as the UART peripheral may draw extra current. 

  • Wow, you replied ASAP. I can see now why people would select your MCU for their embedded system. 

    As you already noticed, the nRF Connect SDK (NCS) is the path forward. Those example you found for Segger Emebedded Studio , are mostly for nRF5 SDK which is our legacy SDK. 

    Glad my Google research was correct. Hopefully you can tell I am doing my homework and not just being lazy and asking questions in this forum. 

    NCS has Zephyr as one of the main components. But Zephyr is not just an RTOS, but it's an RTOS ecosystem where you can find not only the core RTOS but also many libraries, protocol stacks, etc.

    I suspected that was the case however I could not find a link which specifically stated that. Now that you mention this AND thanks to the links you have provided, I have confidence moving forward. 

    To get started it's strongly recommended to follow our nRF Connect SDK Academy course here: https://academy.nordicsemi.com/

    I have not had a chance to view the link, however I will definitely immerse myself in the information information ASAP. 

    Regarding your question on how to put the nRF52 to sleep, I would suggest to take a look at the scheduling documentation here: https://docs.zephyrproject.org/latest/kernel/services/scheduling/index.html

    When there is no active thread (for example by calling k_sleep in the thread, or ask the thread to wait for a semaphore ) the RTOS will automatically put the MCU to sleep.

    Now that is an interesting response from you. I can see now that putting the MCU to sleep is not as simple as running a command such as calling a API function or flipping a bit in a register. When I was Googling my issues, I did run into the "k_msleep()" answer. However, me coming from bare-metal (aka super loop), I could not accept that answer. My train of thought was, "I don't want to put to sleep for X seconds the MCU. I want to put the MCU to sleep indefinitely or until the MCU receives a interrupt." That is why "k_msleep()" was not a suffice answer for me. Hopefully what I am trying to type makes sense? Now I ...see that the RTOS is always running in the background even if I have a main() function and its accompanied while loop?

    You can find that in the blinky sample:

    I did see the blinky example and in fact did use it. Like I said before, sounds like the Zephyr RTOS is always running in the back even with the simple blinky example project? Are all the example project found in the Visual Studio nRF plugins have RTOS implemented? I kind of understood that it was going to be impossible for me to use the Bluetooth in the nRF52832 without implemented the Zephyr RTOS. You see I way traying to use the nRF52832 without the Zephyr RTOS, but it sounds like that is not a good idea. You see in my past projects I have used a two chip solution (MCU and discrete Bluetooth chip) and had to use AT commands running on top of I2C serial communication protocol. 

    Multithreading and scheduling is covered in lesson 7 in the nRF Connect SDK Academy: https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-7-multithreaded-applications/

    I am immersing myself in that link as we speak (or more as I type). 

    Note that with UART sample, you would need to disable UART to achieve low current consumption as the UART peripheral may draw extra current.

    For my current project, that is totally fine. 

    I understand that most if not all of my questions are answered in the links which have been provided. Rest assured, that I will engulf myself in them. However, it doesn't hurt to ask and receive a response beforehand :-). Thanks in advance. 

  • Hi Emilio, 

    Our goal at support is to answer our customers in less than a work day. ( I had a day off yesterday :) )

    nintenodBoy64 said:
    Like I said before, sounds like the Zephyr RTOS is always running in the back even with the simple blinky example project? 

    Correct, the Zephyr kernel always start first before the application. In some applications (\zephyr\samples\basic\threads for example) you don't even see a main() function. 

    If you want to sleep and wait for an interrupt or another thread to finish, you can use semaphore. You can take a look at peripheral_uart sample where the ble_write_thread() wait for BLE to be ready before it continues. When a thread wait, Zephyr OS will put it to sleep and it doesn't consume CPU time/power. 

    You can imagine Zephyr OS like a scheduler. It's not some kind of a module that run all the time to maintain the operation of the chip. So no extra current in the background needed to run Zephyr. When there is no active thread, the current consumption is as low as you go to sleep in bare metal (+ RTC or GPIO interrupt depends on the wake-up source)

    Please let me know if there is something still unclear. Hope that going through the Academy courses would help you to kick start. 

Related