SLEEP Mode in STM32F103 || CubeIDE || Low Power Mode || Current Consumption
46 views
Feb 29, 2020
Purchase the Products shown in this video from :: https://controllerstech.store ________________________________________________________________________________________ STOP MODE ::: https://youtu.be/UtQhc4XV8k4 STANDBY MODE :::: https://youtu.be/TFkU3QD71Pc STM32 Playlist :::: https://www.youtube.com/playlist?list=PLfIJKC1ud8gga7xeUUJ-bRUbeChfTOOBd DOWNLOAD THIS PROJECT FROM :::: https://controllerstech.com/low-power-modes-in-stm32/ ________________________________________________________________________________________ ******* SUPPORT US BY DONATING****** https://paypal.me/controllertech *******Join the Membership******* https://www.youtube.com/channel/UCkdqtSMnhYuMsJkyHOxiPZQ/join Join the Discord Server https://discord.gg/D32JE5wKyD
View Video Transcript
0:08
hello everyone
0:10
welcome to controllers tech today in
0:13
this video
0:14
we will see the low power modes in stm32
0:19
let's take a look at the reference
0:20
manual first
0:24
stm32f103 have three low power modes
0:28
in sleep mode cpu clock is off and all
0:31
other clocks kept running
0:33
in stop mode pretty much all clocks can
0:36
be turned off
0:38
and the last is standby mode which is
0:40
the deep sleep mode
0:43
in this tutorial we will cover the sleep
0:45
mode
0:47
let's start with the stm32 cube id
0:56
first
1:01
i am using version 1.3.0
1:04
and with this version we got a run
1:06
button right here
1:13
create a new project
1:22
i am using stm32f10
1:26
controller give some name to the project
1:30
and click finish
1:38
in the cube mx i am first enabling the
1:41
external crystal for the clock
1:44
next select the sys debug
1:47
serial wire select the uart
1:51
and enable the interrupt
2:02
select the external interrupt on pin pa1
2:07
basically we are going to wake up the
2:09
device using uart interrupt
2:11
and external interrupt on pin pa1
2:15
select gpio nvic
2:18
tab and turn on the external interrupt
2:22
let's see the clock setup i am selecting
2:26
maximum clock
2:27
that is 72 megahertz
2:41
this is connected to the onboard led
2:45
click save to generate the project
3:06
i am creating a variable to store the
3:09
string
3:17
this string will be transmitted before
3:19
the controller goes into the sleep mode
3:50
led will be on for five seconds
3:53
before going into the sleep mode the hal
3:56
ticks must be suspended
3:59
otherwise the systick interrupt will
4:01
wake up the device within one
4:02
millisecond
4:04
turn off the led just to indicate that
4:07
the sleep mode is activated
4:16
finally enter the sleep mode
4:18
[Music]
4:27
main regulator will be on and the wake
4:29
up will be triggered by the interrupt
4:38
when the control reach here the cpu will
4:41
go into the sleep
4:43
after the wake up is triggered next
4:45
statement will be executed
4:48
so it is necessary that we resume the
4:50
hal ticks first
4:52
this string will be printed next and the
4:56
led will toggle few times to indicate
4:58
the wake up
5:12
i am also going to write a uart
5:14
interrupt callback function
5:19
rx data will store the received data
5:21
from the uart
5:26
start the reception in interrupt mode to
5:28
receive only one byte of data
5:31
as i mentioned earlier the wake up will
5:34
be triggered by the uart interrupt
5:36
and the external interrupt on pa1
5:39
to continue this reception we must put
5:42
the same thing inside the callback
5:44
function also
5:46
a little correction guys in f103c8
5:50
the led pin is active low pin
5:54
so to turn the led on we must pull it
5:57
low
5:58
let's build the code
6:07
we will directly run it as the debugging
6:10
is not possible with the sleep mode
6:21
as you can see the debugger shuts down
6:24
automatically
6:30
i will reset the controller sleep mode
6:33
will
6:34
activate in 5 seconds take a look at the
6:37
led
6:38
it goes off means sleep mode is
6:40
activated
6:42
when the button is pressed the external
6:44
interrupt triggers and the device wakes
6:46
up from sleep
6:48
you can see the led blinking
6:51
the while loop will run again and the
6:54
controller will go back to sleep
6:56
on sending the data from the uart the
6:58
interrupt will be triggered and the cpu
7:00
will wake up again
7:03
and the same thing will continue again i
7:06
also want to show the current
7:07
consumption during
7:08
sleep mode for this purpose
7:12
i am using f446re as its easy to measure
7:16
current in nucleo boards
7:19
as you can see during the normal run the
7:22
current consumption is 6.7 milliampere
7:26
when the cpu enters the sleep mode the
7:28
current consumption reduces to 1.8
7:31
milliampere
7:33
when the external interrupt is triggered
7:35
the cpu wakes up again
7:37
and current increases now let's take a
7:41
look at the sleep on exit function
7:44
when the control exits from the
7:46
interrupt service routine
7:48
the cpu will go to sleep
7:53
i will write the callback function for
7:55
the external interrupt line
8:28
these strings will print based on which
8:30
interrupt is responsible for waking the
8:32
controller
8:39
now we will enable the sleep on exit
8:41
function
8:42
but before that i am disabling the sleep
8:45
now function
8:47
also disable the systick resume or else
8:50
it will wake the cpu every one
8:51
millisecond
8:53
let's flash the code
9:08
currently the cpu is running
9:11
as soon as i send some data via the uart
9:14
the interrupt is triggered the processor
9:16
will process the interrupt
9:18
and the cpu will go to sleep as you can
9:21
see
9:22
no other instruction is being executed
9:25
other than the callback functions
9:28
basically the cpu wakes up processes the
9:31
interrupt handler
9:33
and goes back to sleep this is an
9:36
interrupt driven control
9:41
let's disable the exit on sleep
9:44
but make sure that you enable the
9:46
systick before that
9:47
or else the delay functions will not
9:50
work
9:59
i am enabling the sleep now function
10:03
let's build this code and run it
10:18
as you can see when the data is received
10:20
by uart
10:21
the processor goes back to sleep but
10:24
when the external interrupt is triggered
10:27
sleep on exit is disabled and the
10:29
control resumes from the very next
10:31
statement in the while loop
10:33
which means this statement gets printed
10:36
and the led
10:37
will toggle few times after that the
10:40
control will start from the beginning of
10:42
the while loop
10:44
hal tick will be suspended and sleep on
10:47
exit will be enabled again
10:49
as you can see whenever the interrupt is
10:52
triggered from the external pin
10:54
the entire while loop will be executed
10:59
this is it guys i hope you understood
11:03
the sleep mode concept
11:05
i will cover stop mode and suspend mode
11:08
in the upcoming videos
11:11
keep watching have a nice day
#Electronic Components
#Engineering & Technology