0:09
hello and welcome to controllers Tech
0:12
today in this video we will see how to
0:15
establish the communication between the
0:19
I am going to use two hc05 modules one
0:23
as the master and another as the slave
0:27
we will first see how to set these
0:29
modules in their respective modes and
0:31
how to establish the connection between
0:34
then we will communicate between two
0:36
stm32 devices using Bluetooth
0:39
so let's start with the h05 data sheet
0:44
the hc-05 can be used in both the master
0:50
it supports all kinds of board rates
0:52
used in uart communication
0:55
in default configuration it has the
0:59
38400 with one stop bit and no parity
1:03
the default pairing pin is zero zero
1:08
actually this information can change
1:10
with firmware so we will see it
1:13
we can configure the different settings
1:15
for the module in the at command mode
1:19
so let's put the device in the at
1:23
so here I have both the modules on the
1:27
let's see the pins available on this
1:31
we have the enable pin which is used to
1:33
put the module in the at mode
1:36
then there is VCC ground TX RX and the
1:43
the VCC needs to be between 3.6 to 6
1:46
volts so I will provide 5 volts to the
1:50
first I am going to use the AT commands
1:53
so I am connecting the module directly
1:55
to the ft232 USB to TTL converter
2:00
the connection is going to be a cross
2:03
the blue wire is connected to the RX of
2:05
the TTL converter so it connects with
2:08
the TX of the Bluetooth module
2:10
similarly the yellow wire connects
2:13
between the TX of the converter and the
2:17
now connect the enable pin to the 5
2:19
volts so the module can go in the at
2:23
Now power the board and notice the LED
2:28
initially both the red and the blue LEDs
2:31
blinks very fast but once the module
2:33
goes into the at mode the red LED blinks
2:38
this is the confirmation that the module
2:40
has entered the at command mode
2:43
now let's open a Serial terminal to send
2:46
the commands to the module
2:48
this is the port where the USB to TTL
2:51
converter is connected
2:53
we will use the board rate of
2:55
38400 with eight data bits One Stop bit
3:01
let's connect to the device
3:03
make sure to use the carriage return and
3:06
Line Feed to the end of the command
3:08
all right let's send the a t command
3:12
the module returned okay so it is ready
3:16
this is the command we sent just now
3:20
I am only going to cover the important
3:22
commands needed for this tutorial you
3:24
can see the rest yourself
3:26
80 plus orgl can be used to reset the
3:30
module back to its original
3:33
after issuing this command the module
3:36
goes back into its default configuration
3:38
where it is in slave mode with the
3:41
pairing pin is one two three four
3:43
I am going to leave this module in the
3:46
slave mode and set another module in the
3:49
so we would need the address of this
3:52
let's copy this address command and we
3:55
will send it to the module
3:57
the module has returned its address
4:00
we will need this address so the master
4:02
can pair with this module
4:05
we can check the name of the module with
4:14
here the module has returned its name
4:18
hc05 we can also rename the module to
4:23
make sure there is no space when you are
4:27
once the module accepts the command it
4:39
the role command can be used to set the
4:42
module in the master or slave mode
4:44
let's check the current role of the
4:51
it is returning an error
4:58
let me type the command myself
5:04
all right the role is set to zero which
5:09
we want this module in the slave mode so
5:12
let's leave it to this
5:14
the password command can be used to
5:16
check the pairing pin
5:24
it is set to 1 2 3 4 we can change it to
5:28
something else but I am leaving it as
5:31
the uart command is used to configure
5:33
the modules uart settings
5:36
the first parameter is the board rate
5:38
then the stock bit and at last the
5:42
currently the module is configured to
5:44
use the board rate of 9600 with no stop
5:49
I have no idea how it goes with zero
5:52
stop bits but anyway we will configure
5:56
we will set it to use the board rate of
5:59
11 5 200 with one stop bit and no parity
6:03
or write the module confirmed the
6:07
we will also configure the SDM 32 in a
6:11
similar way we don't need to worry about
6:13
other commands this is enough to set the
6:16
module in the slave mode
6:18
make sure to keep the address as we are
6:21
going to need it for the master
6:23
all right let's connect another module
6:26
I am connecting the second module in a
6:32
now disconnect the power and connect it
6:36
you can see the second module has gone
6:42
let's continue with the serial terminal
6:46
let's confirm the at command
6:49
all right the module is responding fine
6:53
let's change its name to hc05 master
7:06
we will set this module in the master
7:08
mode so the role needs to be set to 1.
7:12
right now in the default configuration
7:14
the role is set to zero
7:20
all right the role has been changed
7:31
now we need to connect to the slave
7:38
first we will set the connect mode to
7:40
zero so that this module can only
7:43
connect to the fixed address
7:48
and now we will bind the module to the
7:55
we already have the slave address so
7:59
now replace the colons with a comma
8:07
the module responded okay so it will
8:10
connect to the slave when we power it
8:12
the next time that is all the
8:15
configuration we need
8:17
let's remove the wire and power both the
8:23
the LED blinks fast when the module is
8:26
not connected to anything
8:28
once the connection is established the
8:31
LEDs blinks twice in every two seconds
8:42
to make sure that the connection is
8:44
established I am going to send the test
8:47
data to one module and receive it from
8:51
the blue wire is connected between the
8:53
TX of the slave mode and the RX of the
8:57
and the yellow wire is connected between
8:59
the RX of the master and the TX of the
9:03
basically the data is going to be
9:05
transmitted from the converter to the
9:08
the master will send the data to the
9:11
the slave will then send this data back
9:14
to the converter and we should see it on
9:17
make sure to change the board rate the
9:20
communication board rate is set to 11 5
9:26
here we have received the same data back
9:30
so the connection is established
9:32
successfully and the modules are able to
9:35
communicate with each other
9:36
now let's start the cube ID so to set up
9:40
the things on stm32 controllers
9:45
f103c8 and the f446re controllers
9:49
we will start with the
9:54
give some name to the project and click
9:58
we will start with the clock setup
10:01
the board has 8 megahertz Crystal on it
10:03
and I am running the system at maximum
10:08
now go to uart1 and enable the
10:12
make sure the configuration here is the
10:15
same as what we did for the modules
10:18
the board rate is 11 5 200 with one stop
10:23
now go to the nvic tab and enable the
10:29
the pins pa9 and pr10 got selected as
10:32
the uart TX and RX pins
10:35
we will connect these pins with the
10:39
use the cross connection again with TX
10:41
of the module connected to the RX of the
10:44
sdm-32 and vice versa let's enable the
10:48
uart 2 so that we can communicate with
10:52
enable the interrupt again
10:55
the configuration should be the same as
10:58
the pins pa2 and pa3 got selected for
11:02
the uart so connect them to the USB to
11:07
use the cross connection again with TX
11:10
of the module connected to the RX of the
11:12
sdm-32 and vice versa we always use the
11:16
cross connection as you art so there
11:19
should be no second thoughts here
11:21
that is all the setup we need so click
11:24
save to generate the project
11:26
let's write the code now
11:28
Define an array to store the data
11:32
now in the main function we will receive
11:34
the data in the idle line interrupt mode
11:38
the data will be stored in the data
11:40
array and we will receive a maximum of
11:45
I hope you are familiar with the idle
11:47
line mode if not then check out the
11:50
video on the top right corner
11:52
we will do the same for the uart2 also
11:56
now if all the 64 bytes have been
11:58
received or if the uart detects an idle
12:01
line before that an interrupt will
12:03
trigger and the RX event callback will
12:07
inside the Callback we will check if the
12:10
interrupt is triggered by the usat1
12:13
if it is then we will send the received
12:18
the size parameter holds the actual
12:20
number of bytes received by the uart
12:24
and if it is triggered by the usap2 then
12:27
we will send the data to the uart1
12:31
the hull disables the interrupt after
12:33
each call so in the end we will call the
12:36
receive to idle interrupt function again
12:39
I am passing the parameter huart so to
12:42
make sure the same instance is being
12:44
passed as whichever called this
12:47
all right we are ready with our f103
12:50
code so let's flash it to the board
12:53
now let's create a new project and do
12:56
the same for the f446re
13:05
here I am using the uart4 to connect to
13:09
this is because the pins are easily
13:12
available for you art 4. we will connect
13:15
another Bluetooth module to these pins
13:18
again use the cross connection to
13:21
connect the TX and RX pins
13:24
the configuration should be the same as
13:28
enable the interrupt for the uart4
13:31
I am going to use the ur2 to connect the
13:34
f446 to the computer
13:37
the uox2 routes the data through the SD
13:39
link so it doesn't need any additional
13:43
that is it for the f446 let's generate
13:49
we will use the same that we wrote for
13:56
here instead of U sat 1 we are using
14:01
note the names here uart 4 is not you
14:05
the rest of the code will remain the
14:10
all right let's build and Flash this to
14:15
let me remove the f103 from this
14:23
I am going to connect one of the
14:25
controllers to this computer and another
14:27
controller to another computer
14:29
both the serial softwares are configured
14:32
with the same settings that we used for
14:34
the controllers and the modules
14:36
you can now see how we will send the
14:39
data from one computer to another
14:40
computer using sdm-32 and the Bluetooth
15:46
so the data transmission is working fine
15:50
I hope you understood how to communicate
15:52
using the Bluetooth modules
15:55
you can directly connect your phone or
15:57
computer to the slave module and use
16:00
some Bluetooth serial software to send
16:05
this is it for this video
16:08
the link to download the code and the
16:10
schematics is in the description below
16:13
leave comments in case of any doubt
16:16
keep watching and have a nice day ahead