I was wondering if it is possible to shut an atmel microcontroller down with a software command? I want to shut my controller down either via a remote command via USART or if an internal error happens (as BOD, for example). Unfortunately the whole data sheet tells me nothing about that.
3 Answers
Microcontrollers are not meant to be shut down in the same sense as a PC. They can be put into a low-power sleep mode, and additional hardware can be added to disconnect power externally, but there is no equivalent to turning power off internally.
- 48,488
- 4
- 73
- 103
-
I just want to make sure before disconnecting the external power that everything is in a "proper" state, i.e. that I do not interrupt something. – arc_lupus Mar 06 '15 at 15:08
-
Then you need to write the firmware to get yourself into such a state. – Ignacio Vazquez-Abrams Mar 06 '15 at 15:14
-
-
-
The only reason a PC needs to be shut down safely is because it has hard drives and other hardware that can be stuck in an intermediate state. If you don't have any such hardware connected you can shut it off any time. – Austin Mar 06 '15 at 15:46
Microcontrollers, and indeed CPUs in general, don't understand the concept of "shutting down". They just run and do what they are told.
When you shut down your computer you're not shutting down the CPU, you're shutting down the operating system. The last thing that shutting down of software does is to interface with a part of the hardware on the motherboard to indicate to the power supply to switch the power off. The CPU is still running as per normal at that point since it is the CPU that has to perform the software instructions to send the signal to request the poweroff.
Microcontrollers and CPUs do have different internal power states though where they can turn different parts of themselves on and off - these are often referred to as "sleep" or "idle" modes, and different modes can cause different effects on the internals of the chip (memory loss, etc). The datasheet for your specific chip will detail these modes and what their effects are - as well as how to utilise them. No chip ever has an "off" mode though, only very low power modes.
Boards like the BeagleBone Black which you can "shut down" in software and switch themselves off have a separate power management chip which is instructed by the CPU to switch the power off to the whole board.
- 56,223
- 9
- 105
- 189
There is the 'sleep' instruction. It waits for an interrupt to occur. Clearing the interrupt flag (CLI) will disable them and it will never wake up. However how are you going to tell it's done, without some kind of outside indicator (LED?) BTW, software code is usually referred to as instructions, not commands. :)
- 21
- 2
while (1)with disabled interrupts will do). – Eugene Sh. Mar 06 '15 at 15:16