0:09
hello and welcome to controllers tech
0:12
this is another video covering the stone
0:14
display and as we discussed in the
0:16
previous video today we are going to
0:19
interface the stone hmi display with
0:24
i have already explained how the display
0:26
communicates using the uart in the
0:28
previous video and today we will
0:30
continue where we left last time
0:33
here is the picture of the display here
0:36
you can see there are some pins
0:37
available to connect directly with the
0:41
but the spacing is too wide and i don't
0:43
have the appropriate header pins for
0:47
so i am going to use the uart to usb
0:49
board that comes along with the display
0:51
as it has some set of pins which can be
0:53
used as the tx and rx pins
0:57
after doing some continuity testing i
0:59
have found out that the txb is connected
1:01
to this particular pin right here and
1:04
the rxb is connected to this particular
1:07
we have already discussed that the stone
1:09
hmi outputs the data in the rs 232
1:13
format so in order to convert it to the
1:15
ttl i'm using this is-232 to ttl
1:20
this is the pin out for the ttl
1:22
converter and as you can see on the top
1:25
row the middle pin which is pin number
1:27
three is the rx pin and pin number two
1:32
there are other pins but we are only
1:35
interested in these two
1:37
here is the connection diagram
1:40
the t-x pin from the board connects with
1:43
the r-x pin of the converter and the r-x
1:45
pin from the board connects the t-x pin
1:49
this converter is powered by 5 volts
1:51
which is provided by the stm32 itself
1:55
i tried using the 3.3 volts but it was
2:01
anyway the tx pin from the converter
2:03
connects with the tx pin of the sdm 32
2:06
and the rx pin connects with the rx pin
2:10
one very important thing you have to
2:12
note is that on this side we have a
2:14
cross connection between tx and rx pins
2:17
but on the controller side there should
2:18
be a straight connection t-x connecting
2:20
with the t-x and r-x connecting with r-x
2:24
we also have a potentiometer which is
2:26
connected to the pin p-a-0 that's going
2:29
to be the a-d-c pin and is powered by
2:34
we have a led which is going to be
2:36
controlled by the buttons on the display
2:40
this led is connected to pin pb12
2:44
all right let's see the design now
2:47
i am going to continue from the previous
2:51
this is the label we had in the previous
2:53
project along with the 2 more labels
2:56
that i added for this project
2:58
this particular label is going to act as
3:01
the indicator of the led state so
3:03
whenever we press the button it's going
3:05
to show the current state of the led
3:08
let's rename this to led off by default
3:11
and later we will change this within the
3:16
this label 2 is going to display this
3:19
string and it will remain unchanged
3:22
we have one more label which is label 3
3:25
that's where the value of the
3:26
potentiometer is going to display
3:33
so there are not many changes i have
3:35
made here let's just save this project
3:38
and we will copy this into the display
3:48
all right let's create a new project in
3:52
i am using the sdm 32
3:57
give some name to the project and click
4:04
i am using the external crystal for the
4:10
also configure the serial wire debug and
4:13
change the time base to systick
4:16
let's configure the clock now
4:18
as usual we will use the external 8
4:21
megahertz crystal and the system will be
4:23
running at 72 megahertz
4:30
now we will configure the uart
4:33
i am using the uart 1 and you can see
4:36
the pins p-a-9 and p-a-10 have been
4:38
selected as the t-x and r-x pins we will
4:42
keep the settings as default
4:44
just enable the interrupt
4:47
let's set the pin pb12 as the output pin
4:54
we also need to configure the a-d-c
4:56
channel zero so that pin p-a-0 is
4:59
selected as the adc pin
5:01
not much of the configuration is
5:03
required for the adc and since we will
5:06
be using the poll method even if you
5:08
keep everything default it will be fine
5:11
click save to generate the project
5:14
i think there is some problem with the
5:21
just click yes to resolve the issue all
5:24
right now click save to generate the
5:28
first of all we need to check if we are
5:33
so i am calling the whole uart receive
5:35
in the blocking mode and i am receiving
5:37
the 50 bytes of the data or two seconds
5:39
of the timeout whichever triggers first
5:43
let's define the rx data here
5:49
now build the code and debug it
6:02
i have added the rx data in the live
6:13
so we have hit the break point and if
6:15
you see the rx data we have received 36
6:21
as we have already discussed in the
6:22
previous video when we press the button
6:25
the display sends one set of data and
6:27
when we release the button it sends
6:31
so these 36 bytes actually contain the 2
6:34
sets of data with 18 bytes each
6:37
if you notice here we do have the button
6:40
name led 0 1 which we set in the
6:44
now let's check the instruction manual
6:48
here you can see on pressing the button
6:50
it sends the seven bytes of data
6:52
followed by the button name and its
6:56
these seven bytes of data remain
6:57
constant for whatever button you're
6:59
pressing and the button name is going to
7:01
change as per what we have defined in
7:03
the designer software
7:05
then the last 5 bytes will be the
7:10
so we have the first 7 fixed bytes plus
7:13
the last 5 fixed bytes plus 5 bytes of
7:16
our button name and 1 byte for the state
7:19
totally the 18 bytes of the data
7:23
and this is the reason why i mentioned
7:25
that if we keep the button names of the
7:27
same length it will be better for us to
7:29
program it since we are going to receive
7:31
the same amount of data on pressing both
7:35
so even if you want to program it in a
7:37
simple way by using just the blocking
7:39
functions receiving the fixed amount of
7:42
data it can work pretty well
7:45
but i am not going to do that and that's
7:47
why i am using the receive to idle
7:49
function in interrupt mode if you have
7:52
been following my videos you would know
7:54
about this function since we have
7:56
already covered it in one of the uart
8:00
basically this function triggers the
8:02
interrupt whenever it detects the idle
8:04
line which is when the controller is not
8:06
receiving the data for some fixed amount
8:10
this interrupt will call the interrupt
8:12
handler where we will write the rest of
8:16
for now i am just calling the same
8:18
function again because we know hall
8:20
disables the interrupt after one call so
8:23
we need to call it again all right let's
8:26
write the rest of the code now
8:29
i am defining the pointer to the t-x
8:31
data that we will send to the display
8:35
the is received variable will be set
8:37
whenever we receive some data from the
8:41
and if this variable is set we will
8:43
proceed with the rest of the code inside
8:47
here we will first check the received
8:50
data and we will look for the button
8:53
note here that we are checking the
8:55
received data from the seventh position
8:59
this is because of the data pattern as
9:01
mentioned in the instruction manual
9:04
the first seven bytes are always the
9:06
constants and the button name starts
9:09
from the seventh position
9:11
so in our case we will get led01
9:14
and we are basically comparing that
9:16
particular string with the received data
9:20
once the string matches the string
9:22
compare function's output is going to be
9:24
zero and that will indicate the on
9:27
button has been pressed
9:29
since the on button is pressed we will
9:31
turn on the led by setting the pin high
9:35
then we will reset the receipt variable
9:37
so that we don't enter this loop again
9:40
now we have to send the state of the led
9:45
to do so we will first allocate the
9:47
memory for the tx data
9:51
i am allocating 100 bytes for it
9:56
then copy this entire string into the
10:00
to understand this string let's go back
10:02
to the instruction manual and here we
10:05
will see the label section
10:10
as mentioned here this is the command we
10:12
need to send in order to display some
10:14
string on the hmi module
10:17
so i am using the s printf function to
10:20
copy that entire command into the tx
10:24
this entire command needs to be in the
10:26
string format so we need to put it
10:28
inside double quotes
10:34
also note that the command itself
10:36
contains a lot of double quotes
10:39
to handle this we need to put the
10:41
backward slash before every double quote
10:54
the text we are sending is l-e-d on also
10:57
the label is label 1.
11:04
basically the type is label and which it
11:10
once the data is copied into the tx data
11:13
we will send it using the transmit
11:16
and finally we will free the memory
11:18
allocated for the tx data
11:21
similarly if the received data contains
11:23
led 02 that means the off button must
11:30
we will perform the same things just
11:32
this time the led will be turned off and
11:34
the text will be led off
11:48
all right let's build and debug this
11:52
we have few warnings and that might be
11:54
because i didn't include a few of the
11:58
so let me do that quickly
12:10
all right all the errors are gone now
12:12
and we can debug the code
12:27
you can see the led is turned on
12:33
notice that this time we have only
12:34
received 18 bytes of data
12:37
well this is because there is a small
12:39
delay between when we press the button
12:43
so the receive to idle function triggers
12:45
twice when we press the button and when
12:49
when this function triggers second time
12:52
it overwrites the data from the first
12:55
this is not a problem for us since we
12:57
are only looking for the button name and
13:00
as long as that particular button is
13:01
being pressed or released the code will
13:04
still work keep a note of this
13:06
particular value here as this is the
13:09
only difference between the two buttons
13:12
so you can see the led is responding
13:15
according to the buttons we are pressing
13:18
also note that the led state is changing
13:26
so this part is working well so far and
13:29
we can proceed ahead
13:34
now we need to implement the adc and
13:37
display the potentiometer value on the
13:40
third label we created in the designer
13:44
as i mentioned in the beginning i am
13:45
going to use the poll method for the adc
13:51
so here we just need to start the adc
13:54
then poll for the conversion then get
13:56
the adc value and finally stop the adc
14:01
now we need to send this value to the
14:04
we will use the same method that we have
14:09
allocate the memory for the tx data
14:11
buffer and then copy the command into
14:15
but here instead of the text we will
14:17
pass the format specifier in the s
14:22
percent u is used as a format specifier
14:24
for the unsigned values and we are using
14:27
the unsigned 16 bit variable
14:30
the label is label 3 as we have already
14:33
defined in a designer software
14:40
after the data has been copied into the
14:42
t-x data buffer we will simply send it
14:44
to the uart and clear the memory located
14:49
i am giving 100 milliseconds delay in
14:51
the while loop so that the adc can get
14:54
some time before the next
14:56
run all right now let's build the code
15:07
you can see the value of the
15:08
potentiometer is being displayed on the
15:12
as i am rotating the potentiometer the
15:15
value is also changing
15:21
the buttons are working as usual and the
15:23
led state is also indicating correctly
15:27
everything is working as expected
15:34
so today we saw how we can receive the
15:37
data from the hmi module and display
15:41
we were able to display the string and
15:43
the value of the potentiometer itself
15:46
i hope you understood the video
15:49
the purpose of using the receive to idle
15:51
function was that even if your project
15:53
doesn't have all the elements with the
15:55
same name or don't send the same amount
15:57
of data the receive to idle function can
16:00
handle it and it will only trigger the
16:02
interrupt once the entire data has been
16:06
you can still use the regular uart
16:08
functions if you are sure about the
16:10
length of the data you are going to
16:14
you can check out my previous video on
16:16
this receive to idle function to
16:18
understand it in more detail
16:21
the link to the video will be in the
16:25
that is it for today
16:27
leave comments in case of any doubt
16:30
the link to the project will be in the
16:34
keep watching and have a great day ahead