0:18
hello and welcome to controllers Tech
0:22
this is the eighth video in the SDM 32
0:25
touch gfx series and today we will send
0:28
the data back from the UI to the MCU
0:31
I am going to use the keyboard on the UI
0:33
and send the keyboard data to the MCU
0:37
to do so I will use a structured queue
0:40
which we used while sending the data
0:44
so if you want to understand this video
0:46
better you must watch video number five
0:49
and video number seven
0:51
we will send the data received from the
0:53
UI to the uart and we will do this using
0:56
two different methods
0:58
in the first method we will simply send
1:01
the data from the model by calling the
1:03
whole uart transmit function in the
1:06
in the second method we will create
1:09
another task whose only purpose will be
1:11
to send the data to the uart and we will
1:13
use the message queue to send the data
1:17
the initial setup is the same for both
1:20
the processes so you must watch the full
1:24
I am going to continue the keyboard
1:26
project which we created in the previous
1:32
here I am adding a button to send the
1:41
let's label it as send
1:44
also I am changing its name to button
1:52
we will also add an interaction for this
1:56
when the button is clicked it will call
1:58
a virtual function send clicked
2:01
the rest of the setup is the same as the
2:04
previous tutorial about the keyboard
2:06
with the same texts typographies Etc
2:10
let's generate the project now
2:14
we will open it in the cube ID as usual
2:23
again we will be working with the view
2:25
file so open the screen one view source
2:29
these are the functions from the
2:31
previous tutorial and this time we have
2:34
a new interaction so let's define it
2:36
first in the header file
2:38
this is the function which will be
2:40
called when the send button is clicked
2:43
let's also Define an array of 50 bytes
2:46
which we will send to the MCU
2:49
I am defining two more arrays which will
2:52
be used to store the name and age data
2:55
we need to convert the Unicode character
2:58
data to the regular string format and
3:00
these buffers will be used to store that
3:04
let's build the code once
3:09
now when the name button is clicked the
3:12
keyboard will show up along with the OK
3:16
at this point we want to hide the send
3:20
so set the visibility of the send button
3:27
the same should happen when the age
3:29
button is clicked and the keyboard shows
3:32
now when the exit or the OK button is
3:35
clicked the keyboard will hide and at
3:37
this point we will show the send button
3:43
now let's write the code for the
3:45
send-clicked function
3:47
here we will first convert the data from
3:49
Unicode characters to the regular
3:55
the character data will be stored in the
3:59
the keyboard data is stored in the text
4:01
area name buffer and we will use the
4:03
same to extract the data in the
4:07
here we will simply type cast the
4:10
integer data to the character format
4:12
the process will continue until we hit
4:15
the zero in the text area buffer the
4:18
process will be the same for the age
4:22
this conversion is needed because it is
4:24
very hard to transfer the Unicode data
4:27
now once the data is converted we will
4:30
prepare the data to be sent
4:32
the final data will be stored in the
4:34
data buffer we created earlier
4:48
to send the data we will call the
4:51
function send data in the presenter and
4:53
send the buffer as the parameter this
4:56
function is not defined yet we will
5:00
after sending the data we will clear the
5:03
name buffer and the age buffer
5:17
let's define the function in the
5:19
presenter header file
5:23
now in the source file we will simply
5:26
call the same function in the model
5:35
we will Define the function in the model
5:43
and now finally in the model source file
5:46
we will send the data to the uart
5:49
the whole uark transmit function will
5:51
send the data from the parameter to the
5:55
we need to include the main header file
5:57
along with the string header file
6:04
also Define the u-ut handle as the
6:15
put this part under the if condition
6:23
let's type cast this to the unsigned end
6:31
we need to include some header files in
7:03
or write the project Bill's fine now
7:07
let's Flash the code to the board
7:09
I will use the Hercules serial monitor
7:12
to display the uart data
7:44
here you can see the data is being
7:46
received via the uart
7:49
the data is in the same format as what
7:51
we saved in the data buffer
7:53
so we were able to transmit the data
7:56
from the UI to the uart
7:58
we used a direct approach here by
8:00
calling the transmit function directly
8:04
but let's assume you want to use this
8:06
data in the main file or send it to the
8:09
uart via the main file
8:11
in either case we would need to create a
8:14
structured queue to send this data
8:16
let's open the cube MX to add the queue
8:20
here I am adding one more task you are
8:23
task whose job will be to send the data
8:27
I am keeping the task priority normal
8:31
now let's add a queue with two data size
8:34
this is the same thing we did while
8:36
sending the data from uark to the UI
8:40
let's generate the project
8:46
first we will create a structure in the
8:55
this would contain an array of 50
8:57
characters for the data and a variable
8:59
to store the length of the data
9:03
let's define it as uart data t
9:09
now we will edit the queue definition so
9:11
that it uses the size of the structure
9:17
next we will Define the Q handle as the
9:20
extern variable in the model source file
9:25
also Define the structure which we will
9:28
pass to the queue include the CM sysos
9:33
now in the send data function we will
9:36
first copy the data into the data
9:38
element of the structure
9:43
also update the length element of the
9:47
before sending the structure to the
9:49
queue we will check if there is some
9:51
space available in the queue
9:59
if it is then OS message Q put function
10:02
will be used to send the data
10:05
here we will pass the address of the
10:07
structure to the queue
10:15
that's it for the sending part now we
10:17
have to receive the data in the main
10:24
inside the uart task we will receive the
10:26
data and then transmit to uart
10:29
here we will check if there is some
10:31
message available in the queue if there
10:34
is we will read the message using the OS
10:37
message queue get function
10:39
the data will be stored in the uart data
10:42
structure which we will Define in a
10:45
then we will send the data to the uart
10:48
using the function how you are transmit
10:56
let's define the uart data structure
11:10
let me type cast it to the unsigned int
11:16
all right Flash the code and we will
11:36
we are getting the data successfully on
11:40
so everything is working as expected
11:43
we were able to retrieve the data input
11:45
by the user on the UI and we can use the
11:49
data in our main file
11:51
I hope you understood the video
11:53
the link to download the code is in the
11:58
leave comments in case of any doubt keep
12:01
watching and have a nice day ahead