0:09
hello and welcome to controllers Tech
0:12
this is the fourth video in the AVR
0:14
series using the explained mini board
0:17
and we will continue with the uart
0:19
peripheral which we covered in the
0:20
previous video we saw how to configure
0:23
the art set the board rate and how to
0:26
transmit the data using it in today's
0:29
video we will see how to receive the
0:31
data from uart and then store it in a
0:34
buffer we will use the interrupt to
0:37
receive the data so we need to add a few
0:41
configuration also the connection will
0:44
be the same as the previous video and
0:46
the data will be sent by the
0:48
computer let's start the microchip
0:51
studio and create a new
0:54
project give some name to the project
0:58
okay I am using the same atiny 817
1:03
controller let's copy the entire code
1:06
from the previous video and paste it in
1:09
project I am leaving everything as it is
1:12
and just commenting out the transmission
1:15
part let's take a look at the registers
1:18
again the receiver data register is
1:21
where the data will arrive via the
1:23
uart since we are using eight data bits
1:27
the low bite register can store the
1:29
entire dat data received the highb
1:32
register holds the ninth data bit if you
1:35
are using 9bit data and also the error
1:37
Flags like parity error frame error
1:41
buffer overflow and the receive complete
1:44
flag this receive complete flag is the
1:47
same as what we saw in the status
1:49
register when there is unread data in
1:52
the receiver register this flag is set
1:56
as I mentioned earlier we will be using
1:58
interrupt to receive the dat data we
2:00
need to enable the receive complete
2:02
interrupt in the control a
2:04
register so let's set the seventh bit of
2:07
the control a register to enable the
2:11
interrupt the rest of the configuration
2:13
is same we enable the receiver and
2:16
transmitter then set the asynchronous
2:18
mode with no parity One Stop bit and
2:22
bits set the board rate of
2:25
115200 and clear the transfer complete
2:28
flag note that we don't need to clear
2:31
the receive complete flag as it is
2:33
automatically cleared when we read the
2:35
data from the receiver
2:39
register finally we configure the uart
2:43
pins let's define an array of 10 bytes
2:46
to store the received data and an index
2:49
variable to update the position of the
2:51
data inside the array to receive the
2:54
data we will write an interrupt service
3:07
the interrupt Vector for the U can be
3:09
found in the interrupt Vector mapping
3:12
table here we have three different
3:14
interrupt vectors and we will use the
3:18
interrupt let's write an ISR
3:21
function here we will copy the data from
3:24
the receiver register low bite and store
3:27
it in the buffer we just defined
3:31
update the index variable so that the
3:34
new data gets stored at a new position
3:36
in the buffer our buffer can only store
3:39
10 bytes so if the index value is
3:41
greater than nine we will reset it to
3:44
zero we also need to enable the global
3:47
interrupt in the main function let's
3:50
build the code now the build is
3:53
successful so let's debug
4:00
set a breakpoint inside the ISR function
4:03
and add the RX data buffer to the
4:08
watch this buffer is located at the
4:10
address 3 e00 hex in the memory location
4:15
you can see all the elements of this
4:17
buffer here right now they have the
4:19
value zero I am going to use the real
4:22
term to send the data to the
4:24
MCU it is configured for the board rate
4:27
of 115200 with one stop bit and no
4:34
parity let's send the letter A we have
4:38
hit the break point you can see there is
4:41
no data in the zeroth element of the RX
4:43
data buffer right now let's step over
4:47
this statement here the data has been
4:50
stored in the zeroth element the integer
4:53
value 65 is the decimal equivalent of
4:56
the letter A you can also see this in
4:59
HEX but the aski is not available here
5:03
when the value is stored in the buffer
5:05
the index variable is also increment we
5:08
can see its value by adding it to the
5:12
watch right now its value is one let's
5:24
B it is stored in the first element of
5:27
the buffer and the index variable is two
5:30
now so you see how the index value gets
5:33
updated and this stores the new data in
5:36
the next position in the RX buffer let's
5:39
delete the breakpoint and reset the
5:42
debugger now I am going to send the
5:48
string we need to pause the debugger to
5:51
see the result in the watch here we have
5:54
received the data and they are the
5:56
decimal equivalent values of the asy
5:58
characters we sent you can see the asy
6:01
values by looking at the address where
6:03
the RX buffer is located at let's go to
6:07
the address 3 e00 hex here you can see
6:11
the asy data we sent via the uart let's
6:24
string here we have received it at the
6:27
very next position in the memory
6:30
now all the 10 bytes have been received
6:32
so the next string we send should start
6:35
storing from the beginning of the
6:43
buffer here you can see it so the uart
6:47
reception is working fine we saw how to
6:50
receive the data using the uart and how
6:52
to store it in a buffer for now you can
6:55
use it to receive some fixed amount of
6:58
data in the upcoming videos I will
7:01
release a more flexible Library which
7:03
will make it easy to receive and handle
7:05
the received data this is it for this
7:08
video you can download the code from the
7:11
link in the description leave comments
7:14
in case of any doubt keep watching and