0:14
hello and welcome to controller's tech
0:18
few days ago i covered a getting started
0:20
video on the dwin display
0:23
this is another video with the dwin hmi
0:26
display and today we will see how to
0:28
interface this display with the stm32
0:33
i would advise you guys to watch the
0:34
getting started video first as it will
0:37
help you understand some concepts that i
0:39
might skip in this video
0:42
the hmi displays mostly use u-arc to
0:44
communicate to the microcontrollers so
0:47
we are also going to use the u-r to
0:49
communicate with the s-d-m-32
0:52
for this demonstration i am going to
0:54
control the l-e-d on stm 32 using the
0:57
buttons on the d-win lcd
1:00
let's see the d-win website again
1:04
go to downloads tools
1:07
we have already downloaded these files
1:09
in the previous tutorial and today we
1:12
will download the serial debugging
1:15
this is needed to see the output of the
1:17
lcd whenever we are performing some
1:22
we also need the development guide so
1:27
everything you need to know is in this
1:29
guide and i will explain the components
1:31
i am going to use as the video
1:35
all right let's start with the d gus
1:39
create a new project and give its
1:48
i have downloaded some bitmaps that i am
1:50
going to use as the on off buttons
1:54
this is going to be the background image
1:58
first of all we need to convert the
2:00
images to proper size and generate the
2:02
icl files for the icons and images
2:06
so let's start with the picture
2:18
this is the image we want to resize
2:22
select the screen resolution from here
2:25
now click the image conversion and save
2:28
it in the image folder inside the
2:34
now we will generate the icl files for
2:37
the background image and the icons
2:41
select the background image that we just
2:45
click on generate icl and we must save
2:48
it in the d win set folder in our
2:51
but what should we name this file
2:54
to understand it we should look into the
2:56
flash memory allocation
3:01
as mentioned here the background picture
3:03
icl address is located at 32
3:08
we will also name it 32.
3:15
next we need to generate the icl file
3:17
for the icons we are using
3:20
load the icons in the icl generator and
3:26
the icl address for the icons is at 48.
3:34
so we will name the file 48.
3:37
this completes the i-c-l file
3:39
generations for the assets we are using
3:44
we also need to copy these icon files in
3:49
all right now we can start designing the
3:59
first we will add the background image
4:02
now to display the on off icons we will
4:05
use the variable icon control
4:10
you can find more about this variable
4:13
icon in the development guide itself
4:20
as mentioned here its function is to
4:23
display different icons based on
4:27
when the variable changes the icons get
4:30
switched automatically
4:34
here is the detail of the setting page
4:36
for the variable icon
4:39
anyway i will explain these in detail
4:41
while setting them up
4:43
let's leave the sp to default we are not
4:48
the vp stands for variable pointer and
4:51
we will see it in the end
4:53
we need to set the icon file which is 48
4:58
the variable icon takes the value from
5:00
the variable stored at the variable
5:04
since we are using the on and off icons
5:06
we will keep the value of that variable
5:09
as either zero or one
5:11
the minimum value of this variable is
5:13
going to be zero and we will set this
5:16
green icon corresponding to this value
5:19
similarly the maximum value is going to
5:22
be one and we will set the red icon
5:24
corresponding to this value
5:27
so basically when the variable is zero
5:29
it means the led is off and the lcd is
5:32
going to display the green icon to turn
5:37
and when the variable is 1 the led will
5:40
be on the lcd will display the red icon
5:50
as i mentioned the variable pointer is
5:52
where the variable is going to store
5:55
this is basically a particular address
5:57
in the ram and we can think of it as the
5:59
address of some variable whose value we
6:02
can change using some means
6:05
you can find more about the variable
6:07
pointer in the development guide itself
6:10
if you notice here the ram is 128
6:14
kilobytes which ranges from 0 to fff
6:17
with each address corresponding to 2
6:21
out of this the first 8 kilobytes is
6:24
reserved for the system variables and
6:26
the user can only access the addresses
6:31
so i am going to set the variable
6:33
pointer address to 1100 hexa
6:37
now the variable icon will look for the
6:39
value stored in this particular address
6:42
and based on that value the icons will
6:47
so we have set the variable pointer to
6:49
look for the value stored at this
6:51
particular address but we also need to
6:53
modify the value at this particular
6:57
to do so we will use the incremental
7:01
this touch control will basically
7:03
increment or decrement the value of the
7:07
you can find more details about it in
7:10
the development guide
7:12
check the data auto uploading
7:15
we will set the same variable pointer
7:21
the adjust method is set to increment so
7:23
each time you touch the area the value
7:28
but we want the value to be either zero
7:30
or one so we'll set the over limit to
7:33
cycle this will make sure that whenever
7:35
the value has reached the maximum the
7:38
next touch will set the value to the
7:41
the step length is one
7:43
lower limit is zero and the upper limit
7:47
so if the variable value is zero the
7:50
touch will increment it to one and the
7:52
next touch will reset it to zero and the
7:55
process will continue
7:57
this way we will achieve what we want
8:00
the touch effect should be disposable so
8:02
that long press will only register as a
8:06
all right this is it for the
8:09
click save and generate the project
8:13
before uploading the code to the lcd you
8:15
can debug it and check if everything is
8:20
the icons are changing whenever we tap
8:22
on them this means the variable is
8:24
indeed incrementing and things are
8:28
by the way you can also modify the
8:30
project and see the effect on the
8:32
debugger window in real time
8:35
so this is very helpful if you are
8:37
designing something big
8:39
let's upload the code to the lcd
8:42
select the d-win set directory and it
8:45
will automatically load the files needed
8:47
to be flashed on the lcd
8:50
the lcd is connected to the com11 and
8:52
the board rate should be 11 5 200.
8:56
click start downloading to download the
9:00
all right everything is finished and you
9:02
can see the lcd restarts with the new
9:05
project we just copied
9:10
the buttons are also responding well
9:13
so far everything is fine now we need to
9:16
see what commands does this lcd send
9:18
whenever we press these buttons
9:25
to know this we will use the serial
9:27
debugger we downloaded in the beginning
9:31
make sure the com port is set to proper
9:33
one and the baud rate is set to 11 5
9:43
the lcd is displaying the green button
9:51
you can see there is some command sent
9:53
by the lcd over the uart
9:56
let's understand this command first
10:03
we need to look into the data frame
10:06
here you can see the first data block is
10:09
the frame which is basically the 5-a a-5
10:14
we have also got exactly the same frame
10:18
the next block is the data length which
10:20
basically tells us how long the data is
10:24
in our case it's going to be 6 bytes
10:27
these 6 bytes contain the instruction
10:30
the data itself and the c r c
10:33
the next block is the instruction
10:36
there are 2 instructions we can perform
10:40
zero cross 82 is to write something on
10:42
the lcd and zero cross 83 is to read
10:47
here we are performing the read from the
10:51
basically when we touch the area on the
10:53
lcd in a way we are sending the read
10:56
instruction to the lcd and it replies
10:59
back with the value of the variable
11:02
after instruction we have the data
11:04
itself which can be up to 249 bytes long
11:09
let's see some examples to understand it
11:12
this is the example to read the variable
11:15
pointer this here is the output from the
11:19
first we have the frame data length and
11:22
the read instruction
11:24
the next 2 bytes are the address of the
11:26
variable pointer which in our case is
11:31
the same what we set in the incremental
11:38
after the address there is one the
11:41
number of words to read
11:43
we are also reading one word
11:46
the last two bytes are the value stored
11:50
in our case the value is one
11:53
so we press the green button and the lcd
11:56
sent one in the output and the button is
11:59
on pressing the red button everything is
12:02
the same except the value is zero
12:05
basically when the lcd displays the
12:08
green button the led will be off
12:11
on pressing the green button the lcd
12:14
will send one in the output which will
12:18
the lcd will display the red button now
12:21
and on pressing it the lcd will send a
12:24
zero to the output which will turn off
12:28
so all we have to look for is this last
12:30
byte and whether this byte is one or
12:32
zero will control the led
12:35
if you count here there are a total of 9
12:38
bytes in this command
12:40
let's keep that in mind and now we will
12:43
create a new project in stm32
12:48
i am using the stm 32 f103 controller
12:53
give some name to the project and click
12:57
first of all we will do the clock setup
13:00
i am choosing the external high speed
13:03
crystal for the clock
13:05
the blue pill has eight megahertz
13:06
crystal and we will run the system at a
13:09
maximum 72 megahertz frequency
13:12
enable the serial wire debug
13:15
now we will enable the uart to
13:17
communicate with the lcd
13:20
i am choosing the uart 1 for this
13:23
make sure the board rate is set to 11 5
13:28
leave everything to default here
13:30
enable the interrupt as we are going to
13:33
use interrupt to receive the data from
13:37
that's all the configuration required
13:39
click save to generate the project
13:42
by the way i have soldered a 4-pin
13:44
header on the lcm module the module has
13:48
the pins tx4 tx2 rx2 and rx4
13:53
i am connecting the tx2 to the rx pin of
13:56
the stm32 and rx2 to the tx pin of the
14:00
stm32 let's write the code now
14:06
first of all we will define an array to
14:08
store 9 bytes of the data
14:13
now in the main function we will receive
14:15
the uart data in the interrupt mode
14:19
we will set the interrupt to trigger
14:20
after 9 bytes have been received
14:23
once that happens the receive complete
14:26
callback will be called and we will
14:28
write the rest inside it
14:30
if you remember the hal disables the
14:33
interrupt after triggering it once so we
14:35
will again call the interrupt receive
14:38
this will make sure the data is received
14:43
now the data is stored in the rx data
14:45
array and if you remember only the last
14:48
byte of this data is significant to us
14:51
we will process this data in the while
14:55
here we will check the last byte of this
14:57
array and if this byte is 1 we will turn
15:00
on the led at pc 13.
15:03
the led on the blue pill is active low
15:06
so to turn it on we must pull the pin
15:09
similarly if the last byte is zero we
15:12
will turn off the led by pulling it high
15:15
i forgot to enable this pc 13 led in the
15:21
set this pin to output and build the
15:25
right everything is set now build the
15:40
i am adding this r x data in the live
15:44
since the lcd outputs the hexadecimal
15:46
values we need to change the format to
15:50
remember that after changing it you need
15:53
to restart the debugger or else it won't
15:55
show the correct values
15:58
let's run the code now
16:02
right now the green button is displaying
16:04
on the lcd and the led is turned off
16:08
when we press the button the led turns
16:12
you can see the rx data array the last
16:14
byte is 1 indicating to turn on the led
16:18
when the red button is pressed the last
16:20
byte is zero and the led turns off
16:32
you can see the led is responding well
16:35
with respect to the icons on the lcd
16:38
so i hope you understood how to
16:40
interface this d when lcd with sdm 32
16:44
you can interface it with any
16:46
microcontroller which has the uart as it
16:49
needs only you are to communicate
16:51
this is it for the video
16:54
i hope you understood the logic well
16:57
let me know if you want me to continue
16:59
this series in the comments below
17:02
you can download the code from the link
17:06
keep watching and have a nice day ahead