0:09
hello and welcome to controllers Tech
0:12
this is the sixth video in the SDM 32
0:15
uart series and today we will
0:17
communicate using a single wire the half
0:20
duplex mode we have already covered how
0:23
to send and receive data via the U using
0:26
different methods one thing which was
0:29
common in all the previous videos was
0:31
that we were using the full duplex mode
0:34
that means there were two wires for the
0:36
communication one for transmitting and
0:39
another one for receiving single wire
0:42
mode is used to transmit and receive
0:44
data only using one wire but at a time
0:48
at one particular time the MCU can be
0:51
either a sender or a receiver it can't
0:53
be both and that is why this is called a
0:56
half duplex mode let me give a quick
0:59
overview of of what is going to be
1:00
achieved in this video I am going to
1:03
transfer data between two
1:06
MCU they both are not going to be
1:08
nuclear boards this picture is just for
1:12
demonstration since we only have the TX
1:14
pin available in the half duplex mode
1:17
they will be connected to each other
1:19
initially both the mcus will be in the
1:22
receiver mode when the button on one of
1:24
them is pressed that MCU will become the
1:27
transmitter it will send some data via
1:30
the TX pin and the receiver will receive
1:33
that data we will see the data in the
1:37
expression once the data transmission is
1:40
complete the sender MCU will again go in
1:43
the receiver mode when the button is
1:45
pressed on the second MCU it will become
1:48
the transmitter and transmit the data
1:50
via the TX pen the receiver will receive
1:53
this data and we will again see this on
1:56
the live expression after transmission
1:59
if it will also go in the receiver mode
2:02
Let's Start the QBE ID and create a new
2:06
project I am using SDM
2:11
re give the name to the project and
2:14
click finish let's set up the clock
2:17
first I am going to bypass the external
2:21
Crystal so that it can use the one from
2:23
the SD link on the board the crystal is
2:26
8 MHz and we will run the system at
2:31
MHz let's set up the U now we can't use
2:36
the u 2 as it is connected to the SD
2:39
Link in the nucleo boards let's use the
2:42
uart one instead enable the single wire
2:46
half duplex mode here you can see the
2:49
pin pa9 is configured as the TX pin and
2:52
this is the only pin we have we will
2:55
leave the configuration to default but
2:57
make sure the same configuration is is
2:59
used on the other MCU as well now go to
3:03
the gpio setting click on the pin pa9
3:07
and enable the pullup for it this is
3:10
necessary to receive the data some mcus
3:14
like SDM 32 f103 C8 do not have the
3:17
option for the pull-up here so you need
3:19
to connect One external pull-up resistor
3:22
to the line now go to the nvic tab and
3:26
enable the art Global
3:28
interrupt we will use the interrupt to
3:31
receive the data the user button on this
3:34
nucleo board is connected to the pin
3:36
pc13 so configure the pins as the
3:39
external interrupt pin now go to the GPO
3:44
tab to configure this pin let's enable
3:47
the pullup for this pin so when we press
3:49
it it will be pulled low to the ground
3:53
the interrupt will trigger for the
3:54
rising Edge that is when the button is
3:57
released go to the end viic Tab and
4:01
enable the interrupt for the XD pin that
4:04
is all the configuration we need click
4:10
project let's build it
4:16
once all right here in the uart one
4:19
initialization you can see that the uart
4:21
is initialized in the half duplex mode
4:25
we only have three functions for half
4:27
duplex mode one is to enable the
4:30
transmitter next to enable the receiver
4:35
initialization as I mentioned in the
4:37
beginning the MCU will always be in the
4:40
receiver mode unless the button is
4:42
pressed so let's enable the half duplex
4:45
receiver mode now we can use any method
4:48
to receive the data I will use the
4:51
receive to idle in in the interrupt mode
4:53
to receive 30 bytes of data once all 30
4:57
bytes have been received or idle line is
5:00
detected before that an interrupt will
5:02
trigger and the RX event call back will
5:05
called here we will again call the same
5:08
function so as to maintain the
5:14
reception you can simply leave it to HW
5:20
one let's define the RX data buffer to
5:27
bytes the index variable will be used in
5:31
transmitting TX data will store the data
5:38
sent the is clicked variable will track
5:41
if the button is pressed or not now we
5:44
will handle the gpio external
5:47
interrupt when the button is pressed the
5:54
called inside this call back we will
5:57
check if it is called by the pin number
6:01
if it is then we will check the value of
6:04
variable if the variable is zero we will
6:08
set it to one otherwise nothing will
6:11
happen inside the while loop we will
6:14
again check the value of the is clicked
6:16
variable if the variable is one that
6:19
means the button is pressed and we need
6:21
to send the data we will prepare the
6:26
first basically we will copy this string
6:29
along along with the value of the index
6:31
variable to the TX data buffer each time
6:35
the button is pressed the index variable
6:37
will increment so that there will always
6:41
send now that we have the data let's put
6:44
the uart in the transmitter
6:46
mode then we will send the data to the
6:50
uart the Sint F function Returns the
6:53
total length of the string so we will
6:55
use it as the size parameter in the
6:57
transmit function once the data has been
7:00
transmitted put the uart back in the
7:03
receiver mode also reset the is clicked
7:06
variable so that this Loop doesn't run
7:09
again let's build the code now we need
7:12
to include the standard IO header file
7:15
for the S print after to work let's also
7:18
add a small delay here so that we don't
7:20
get the key debounce let's build and
7:27
now here I have added the RX data and
7:31
the index variable in the live
7:33
expression I have the SDM 32
7:36
f411 Discovery board as the second
7:40
MCU here you can see the pin pc6 is
7:43
enabled as the U 6tx pin the rest of the
7:47
configuration is the same as what we
7:49
have seen for the nucleo board you can
7:52
see here it is exactly the same code as
7:55
what we wrote for the nucleo board let's
7:58
build and debug it this board is
8:01
connected to another computer so we will
8:04
see the live debugger for both the
8:07
simultaneously the U1 TX pin pa9 from
8:10
the nucleo board connects to the U 6tx
8:13
pin pc6 on the Discovery board you can
8:17
see both the debuggers now let's click
8:20
the button on the Discovery board I am
8:23
pressing the button but there is no data
8:25
received on the nucleo board you can see
8:28
the index X variable is two which
8:31
indicates that the data was indeed sent
8:33
but it was not received the same happens
8:37
when I press the button on the nucleo
8:39
board this is happening due to different
8:42
power sources we should at least have a
8:44
common ground between both the boards so
8:48
I am connecting the ground between both
8:50
the boards let's try sending the data
8:57
again now you can see the the data has
8:59
been received by the nucleo board the
9:03
value of the index variable is three and
9:05
the same data has been received by the
9:08
nucleo board let's press the button on
9:11
the nucleo board now the index variable
9:14
on the nucleo board is two and the same
9:17
data has been received by the discovery
9:19
board keep an eye on the value of the
9:22
index variable and the data received by
9:25
the nucleo board let's keep pressing the
9:28
button on the Discovery board the data
9:31
is being received by the nucleo board
9:34
and the value is the same as the index
9:36
variable on the Discovery board so the
9:39
communication is working fine both ways
9:42
we are able to use one wire to transmit
9:45
and receive data between two SDM 32
9:48
boards this is it for this video I hope
9:52
you understood the communication using
9:54
half duplex mode you can download the
9:58
code from the link in the description
10:01
leave comments in case of any doubt keep
10:04
watching and have a nice day