0:12
this is yet another video covering the
0:14
rivety display and today we will send
0:17
the data from uart to the UI
0:19
we will simply receive something from
0:21
the uart and then display it on the GUI
0:24
I will continue where I left the
0:27
previous project so the ad functionality
0:29
will still be present in the tutorial
0:32
here is the previous project we worked
0:36
let's add another text area to it
0:39
I am using the same large typography and
0:42
the name should be text area you art
0:44
the Wild Card range is already set for
0:48
so this is it for the configuration
0:50
let's generate the project and open it
1:00
in the meantime let's see the datasheet
1:06
here you can see the board has RS 485
1:10
interface and rs-232 interface
1:16
along with these the expansion connector
1:19
also has the usart1 pins and one uart
1:22
8tx pin for the modbus
1:25
for convenience you can use the rs-232
1:29
but since I don't have a converter for
1:31
this I am going to use the rs-485
1:35
all of them work on the uart so using
1:39
you can check out my previous video
1:41
explaining the rs-485 communication
1:45
here we need only two pins pin an A and
1:50
I am using a USB to RS 485 converter
1:54
module with the computer
1:56
the pin a from the module connects to
1:58
the pin a of the board and the pin B
2:00
connects with each other
2:02
the ball already has RS 4852 art
2:06
converter so we don't need to worry
2:08
about the signal level
2:10
let's see the project now
2:13
this is the same project we made for LED
2:15
control and I will continue with the
2:19
here in the main file you can see the
2:22
use art header file is already included
2:25
in the initialization section the uart1
2:28
is being initialized along with uart4
2:30
and uart 8. let's see the code for it
2:38
this section initializes the uart 4 and
2:42
if you note here there is a function to
2:44
initialize the rs-485
2:47
this means that the uart 4 is connected
2:49
to rs485 and we will work with it
2:53
if you know about the rs-485 module
2:57
there is a driver enable pin
2:59
this pin can be used to set the module
3:02
in the receive mode or the transmit mode
3:05
here that a pin's polarity is set to
3:08
high which means that the pin is active
3:11
so to pull the signal High we pull the
3:14
pin high and to pull the signal low we
3:19
the uart 8 has no initialization here
3:23
the uart1 is initialized normally
3:26
in the initialization of uart2 the
3:29
hardware flow control is enabled
3:31
so this must be connected to the rs-232
3:36
as I mentioned I am going to use the
3:39
rs-485 port so I will use the uart4
3:43
irrespective of whatever you are to use
3:45
the code will remain the same
3:48
all you need to do is change the uart
3:52
let's quickly see the MSP initialization
3:57
here you can see the d e pin is actually
4:00
the pin p of 15. keep this in mind as we
4:04
would need it to put the port in the
4:07
the uart 4 initialization is already
4:10
called so we are good here
4:12
we don't need anything in the main file
4:14
let's head over to my file.c which we
4:18
created in the last video
4:20
here we already have the LED related
4:22
code from the previous video so I will
4:25
write the uart code separately
4:27
most of the things will remain the same
4:30
so let's copy this complete code and
4:32
paste in the uart section
4:36
now we will change the word led to the
4:47
all right let's understand things
4:50
first we Define the task handle and the
4:55
then we have the attributes for the uart
4:58
the stack size is 512 words and priority
5:05
next Define the attributes for the uart
5:07
Q which will be used to send the data to
5:12
then we write the functions to
5:13
initialize the uart task and uart Q
5:17
and finally we have the task function
5:20
which we will write from scratch
5:22
since we will be sending the data in the
5:25
string format we need to create a
5:29
I have covered this in my touch gfx
5:31
video you can see on the top right
5:34
here the structure consists of two
5:37
elements a character array to store the
5:39
data and an integral variable to store
5:42
the length of the data
5:45
let's define the structure uart data s
5:48
which will be used to store the
5:52
the queue will only have one element and
5:54
the size of this element will be the
5:56
size of the structure
6:01
we also need to define the uart handle
6:04
so copy it from the uark.c file and
6:07
Define it as an external variable
6:11
now I could simply use the basic uart
6:14
functions to receive the data here but
6:16
let's say that I want to use the idle
6:19
line interrupt to do so
6:21
let's also assume that I don't know how
6:24
to initialize the interrupt for the uart
6:27
so far we have used the cube MX to
6:30
initialize the interrupts for us but we
6:32
know that we can't use Cube MX with the
6:36
so here is what we will do
6:39
copy the project to another location
6:42
now open the ioc file in Cube MX
6:49
let's see who you are for
6:53
here you can see the pins being used for
6:58
I want to initialize the interrupt for
7:00
the uart4 so let's enable it
7:03
don't make any unnecessary changes in
7:08
generate the code now
7:10
don't open the project instead open the
7:13
folder now go to the CM7 core source and
7:22
here you can see the interrupt has been
7:24
initialized so let's copy this
7:27
you can put it in the uart source file
7:29
itself but since it's initialized after
7:32
the uart I am just putting it here in
7:34
the task function another Edition that
7:37
would have happened is in the interrupt
7:40
let's copy the uart handle and paste it
7:43
in the interrupt file
7:47
the uart4 interrupt Handler is also
7:50
created so we will copy it in our
8:00
that's all the changes happened when we
8:03
added the interrupt let's write the rest
8:07
first we will set the d e pin low so
8:10
that the rs485 can be put in the
8:15
now we will receive data in the receive
8:17
to idle interrupt mode
8:19
the data will be stored in the RX buffer
8:22
and the maximum we can receive 64 bytes
8:26
let's define this RX buffer
8:29
since we don't need anything else from
8:31
this task let's give a bigger delay here
8:38
now when the uart has received 64 bytes
8:41
or it detects an idle line before that
8:44
and interrupt will trigger this will
8:47
call the RX event callback function
8:50
here we will first copy the data from
8:52
the RX buffer into our structure
8:58
I am setting the last data byte as the
9:01
string Terminator and updating the
9:03
length parameter with the new size
9:06
now we will send the structure to the
9:09
so first we will check if there is some
9:12
space in the queue if there is then put
9:16
the priority in timeout both are set to
9:20
and finally call the receive function
9:24
so that is all we need to do for sending
9:27
the data let's build the code now
9:32
the string header file needs to be
9:37
now Define these newly created functions
9:40
in the my file header so that we can
9:42
call them in the main file
9:53
all right now we need to receive this
9:55
data in the model and finally display it
9:59
so let's start with the model first
10:03
let's define the uart Q handle as the
10:05
external variable and also Define a new
10:08
structure to save the received data the
10:11
model tick function is called every time
10:13
the frame is refreshed on the UI so we
10:16
will write our code inside it
10:18
we will first check if there is some
10:21
data available in the queue if there is
10:24
then we will get the data and store it
10:27
in the structure we defined
10:30
now copy the data from the structure and
10:33
store it in an array
10:37
we need to define the character array in
10:40
the model header file
10:48
once the data has been stored call the
10:51
function you art display in the model
10:53
listener we need to Define this function
10:56
in the model listener
11:00
make sure the function has an empty
11:05
since the function has an empty
11:06
implementation it will look for the same
11:09
function in the presenter now
11:11
so we will Define the same function in
11:13
the presenter header file and write the
11:16
code for it in the source file
11:18
here we will call the same function in
11:22
so now Define it in the view header file
11:29
finally we will write the code in the
11:33
here we will use the Unicode string copy
11:36
function to copy the data into the text
11:39
area you out buffer I guess I forgot to
11:42
implement the wildcard for the text area
11:45
let me do this quickly
11:50
the buffer should have one Higher byte
11:52
than the maximum data you are displaying
11:55
regenerates the code
11:59
let's refresh the project once
12:05
it is still not showing in the
12:07
autocomplete so let me copy it from the
12:10
screen view base file
12:25
after copying the data into the buffer
12:28
we will invalidate the text area so the
12:31
changes can take effect
12:34
the string copy inclusion is missing so
12:37
let's include the C string
12:42
or write the code builds fine
12:45
go to touch gfx and Flash the code to
12:55
I have connected the rs-485 module to
12:59
the computer and it is connected to com
13:06
you can see the uart data is being
13:09
displayed on the text area
13:13
here the data has exceeded the space
13:15
available for the text area
13:18
this is because I forgot to include the
13:20
word wrap in the code
13:22
here in the view file set the white text
13:25
action to word wrap this will fix that
13:28
issue and the text will automatically
13:30
display on the next line
13:43
the LED is working fine and now we have
13:48
this completes today's video about
13:51
sending the data from you out to the UI
13:54
I hope you understood the procedure
13:57
I am still working on the ADC and once I
14:00
interface it successfully I will make a
14:02
video on it the link to download the
14:05
code is in the description below
14:08
leave comments in case of any doubt
14:10
keep watching and have a nice day ahead