0:21
everyone welcome to controllers tech
0:26
today in this video we will see how to
0:30
wireless transceiver with sdm32
0:34
i will first cover how to set up hc12
0:38
and later i will use stm32 to do the
0:41
communication between them
0:44
so let's start with the setup first
0:47
here is the hc12 i am going to use
0:52
i have one more obviously and it looks
0:56
if you compare them side by side you can
1:01
yes i got a fake one but unintended of
1:05
there is crucial difference between both
1:08
the range is an issue for the fake hc-12
1:13
and i will leave the link for the fix in
1:16
i have already fixed the range so i am
1:21
as you can see at the back here we have
1:25
ground rx tx and the set pin
1:31
so i am connecting ground to ground 5
1:35
tx to rx and rx to tx
1:39
now the set pin must be pulled low for
1:42
so connect that to the ground
1:52
i have connected it to the ftdi serial
1:57
and you can see in the device manager
2:02
so let's open the console.com4
2:12
choose the board rate of 9600
2:22
this 9600 board rate is default for hc12
2:26
and it is mentioned in the data sheet
2:42
let's open the connection type the a t
2:46
and send you can see the response
2:53
see what other commands that we can use
3:00
this is to change the baud rate to
3:03
change the communication
3:04
channel a t r is used for inquiry
3:14
let's inquire the channel
3:21
i think it's uppercase c
3:26
yes the communication channel is set to
3:32
board rate is set to 9600.
3:39
you can type at plus rx to inquire about
3:42
all the parameters at once you can see
3:46
the details in the data sheet
3:56
the transmitting power is set to max and
4:08
i am leaving everything to default as
4:11
setup you can change them according to
4:19
now let's create the project in cube id
4:23
i am going to use both stm32f446 and
4:29
each hc-12 first i am creating the
4:42
give some name and click finish
4:48
select external crystal for the clock
4:55
now you out one is where the device will
4:58
turn on the interrupt if you want to use
5:03
use the baud rate of 9600.
5:07
uart2 is for communicating with the
5:11
same setup is required here too
5:20
now the clock setup i have eight
5:25
and i want the system to run at maximum
5:31
click save to generate the project
5:38
here is our main file
5:46
here i am going to send some data to the
5:56
and i want the process to repeat every
6:09
we have no errors so let's go ahead and
6:13
as i am connecting two different mcus to
6:18
i will face some issues with the sd link
6:21
to avoid that connect the first sd link
6:26
now in the debug configuration select
6:29
the sd link serial number
6:31
and tap on scan as there is only one sd
6:36
it will show up and now this particular
6:39
project will only use this particular sd
6:42
link the code is successfully flashed
6:50
this is it for the transmitter now i am
6:53
going to create another project for the
6:56
here i am using f103c8mcu
7:00
and the rest of the setup will remain
7:24
here in the main file create an array to
7:27
store the received data
7:36
now how you are receive will receive 22
7:39
bytes of data in the blocking mode
7:44
and then transmit that data to the
7:53
let's build it and flash
7:58
now i am connecting the second sd link
8:02
check the serial number again and tap
8:06
you can see both the sd links are being
8:10
as i already know that this one is the
8:13
so select the second and click apply
8:16
now this project will always use the
8:20
regardless of how many are connected
8:23
so we have flashed both transmitter and
8:28
let's see the connection once this wire
8:32
is connected between the rx pin of the
8:34
hc-12 and the uart 1tx
8:40
this one is connected between the tx of
8:44
and the uart 1 rx vcc is connected to 5
8:50
and note that the set pin is not
8:54
we need to leave it like that for
8:58
and while using the at commands ground
9:03
the similar connection is in the
9:07
tx to rx and rx to tx
9:11
also i have connected the uart two pins
9:15
to communicate with the computer
9:21
let's open the console and set the com
9:23
port for the receiver
9:38
as you can see the data is receiving
9:42
as we expected i have tested this for a
9:47
and it works as stated obviously i
9:51
couldn't test for two kilometers range
9:53
but i think it should work for a fairly
10:13
now let's move to the more complex part
10:15
and here we will do a two-way
10:16
communication between both the hc-12
10:21
to do so i will use my uart ring buffer
10:25
i already have a video on it you can
10:28
check on the top right corner
10:30
let's include the library files
10:34
put the c file in the source directory
10:36
and header file in the include directory
10:40
do the same for the second project also
10:48
let's modify the f103 project first
10:57
include the uart ring file
11:01
change the header file according to your
11:09
now we need to copy this and paste it in
11:16
and change the default interrupt handler
11:34
now in the main file first define the
11:52
in the main function call the ring
11:54
buffer initialization function
11:59
and now if the data is available from pc
12:02
it will read it and send it to the
12:06
and if the data is available from device
12:10
and send it to the computer that's all
12:20
we need to do the same steps in the
12:24
i will just fast forward this part
12:49
let's build it and flash to the mcu
13:15
flash the first one also
13:22
so we are all set now
13:29
let's open another instance of this
13:33
so one is at com port 3 and another at
13:38
here the pink color is the one i am
13:40
sending and black color is the one
13:48
you can see the communication is working
13:52
and as this is using ring buffer we can
13:54
send random number of characters also
14:53
this is it for this video i hope you
14:58
you can test different board rates and
15:02
whatever suits the need you can download
15:05
the code from the link
15:06
in the description keep watching
15:10
be safe and have a nice day ahead