0:40
hello everyone welcome to controllers
0:45
today in this tutorial we will interface
0:48
df player mini with stm32
0:51
df player works with very simple
0:55
which needs to be transmitted using uart
0:58
let's start by creating a project in
1:02
first i am using stm32f103 for this
1:12
give some name to the project and click
1:21
here is our cube mx i am selecting
1:25
external crystal for the clock
1:28
select serial wire debug
1:31
i am using ut1 to send commands
1:35
make sure the board rate is 9600 bits
1:40
i am going to use three buttons to
1:45
that's why i am selecting these pins as
1:48
let's go to the clock setup now i have
1:52
eight megahertz external crystal
1:54
and i want the controller to run at 72
1:58
click save to generate the project
2:10
first of all we need to copy the library
2:14
so copy the c file to source and header
2:17
file to include directory
2:26
click refresh and you can see the files
2:30
let's take a look at the data sheet
2:37
as you can see here it supports fat 16
2:40
fat 32 formats for the sd card
2:44
there are 30 levels of volume and other
2:49
you can read them as mentioned here
2:52
the default board rate is 9600
2:56
and now the very important thing the
2:59
standby current is 20 milliamperes
3:02
i will tell you more about this in a
3:06
this is the diagram of df player mini
3:09
we are going to use only this side
3:13
let's take a look connection now i am
3:16
using external power supply
3:23
rx pin from the df is connected to tx
3:26
pin of the controller
3:27
which is pin pa9 and tx pin
3:31
from the df is connected to rx pin of
3:35
which is pin pier 10. speaker 1 and
3:38
speaker 2 pins are connected to the
3:41
and negative of the speaker
3:47
these three buttons are connected to pin
3:54
this button is for previous selection
3:56
this one is for pause or play
3:58
and this is for next song selection
4:06
coming back to the external power supply
4:09
while testing i found that df player
4:12
needs around 25 milliampere of current
4:15
during the song is playing f103 was not
4:19
able to supply this much current
4:21
even with the usb connected so
4:25
i switched to the external power supply
4:31
even in the data sheet it's mentioned
4:34
that it takes 20 milliamperes of idle
4:38
let's go back to our main file
4:45
we need to include the library in our
4:54
let's see the df dfplayer.c file now
4:58
here you can change the uart according
5:00
to the one you are using
5:02
the source is defined as from the sd
5:06
i will get back to this in a while
5:12
define the pins that you are using for
5:24
let's see these defines now
5:29
start byte is zero cross seven e
5:35
end byte is zero cross e ef
5:38
the command sent to the df player have a
5:41
and that is start byte
5:44
version command length command feedback
5:48
parameter 1 parameter 2 16-bit checksum
5:58
the command length is 6 as mentioned
6:01
because it does not count the start
6:03
check sum and the end bytes
6:08
we are not going to use feedback so i
6:10
have defined it 0 here
6:16
send command function will send the
6:18
command to the df player
6:21
it first calculates the checksum
6:24
the command sequence is same here too
6:28
we have start byte version command
6:32
command feedback parameter 1
6:35
parameter 2 check sum high byte lower
6:43
and then it sends this array to the uart
6:51
df in it is to initialize the player and
6:54
it takes volume as the parameter
6:57
basically we send zero cross three f
7:06
you can see here this is the command to
7:09
initialize the player
7:11
and we need to send the parameters also
7:14
if you scroll down the example is
7:17
provided in the data sheet
7:20
this is the sequence of commands need to
7:23
for the tf card we have command
7:26
feedback parameter 1 and parameter 2.
7:30
the parameter 2 is 0 cross 0 2 for the
7:38
that's why i have defined it as source
7:41
you can change it and see the other
7:43
parameters in the data sheet
7:47
then it sets the volume
7:54
0 cross 0 6 is the command to set the
7:58
along with the parameter which acts as a
8:10
df next function is to play the next
8:17
this command does not need any parameter
8:20
this is command to play previous song we
8:33
check key function checks if the key is
8:37
if the song is playing then it will be
8:39
paused or if it is paused
8:41
then it will resume the play then we
8:44
have a button for previous
8:46
and a button for next song
8:52
now let's start programming
8:56
initialize the df player i am keeping
9:04
start the play from the first song
9:10
in the while loop we will keep checking
9:12
for the button pressed
9:14
let's build and debug this
9:23
before starting i want to show you my sd
9:28
there are six mp3 files
9:32
you should also number them like i have
9:34
done it here let's run this
10:48
this is it guys i hope you understood
10:52
how to program this df player mini
10:55
you can download the code from the link