1
00:00:01,140 --> 00:00:02,260
Hello, welcome back.

2
00:00:02,280 --> 00:00:09,540
In this lesson, we going to develop a number of powerful drivers that we shall use in the rest of our

3
00:00:09,540 --> 00:00:15,540
course so that we can try out much more complex systems who need these drivers when we start dealing

4
00:00:15,540 --> 00:00:19,560
with interrupt with regards to our free hour, Toscano.

5
00:00:20,220 --> 00:00:27,510
So what I'm going to do is I'm going to make a copy of this first project we have here and then or just

6
00:00:27,510 --> 00:00:30,720
continue from the I'll copy and paste.

7
00:00:31,760 --> 00:00:37,430
This project doesn't require an artist, but I'm making a copy because if I create a new project, I

8
00:00:37,700 --> 00:00:45,770
need to include the path and the forward directory for the driver's licenses and the whole drivers.

9
00:00:45,770 --> 00:00:46,580
But I don't want to do that.

10
00:00:46,580 --> 00:00:49,220
So I make a copy of an existing project.

11
00:00:49,790 --> 00:00:51,590
So I call this number 19.

12
00:00:53,190 --> 00:00:55,380
And know name the project, some driver's.

13
00:00:59,350 --> 00:01:01,540
Like this, and then I'll say copy.

14
00:01:03,150 --> 00:01:04,920
OK, it's over here.

15
00:01:05,500 --> 00:01:06,630
I'm going to click call.

16
00:01:07,870 --> 00:01:16,510
May not see and I'm going to clean everything with regards to the artists, I'm going to come over here

17
00:01:16,510 --> 00:01:17,050
and then.

18
00:01:19,470 --> 00:01:20,700
I'm going to start from the top.

19
00:01:21,300 --> 00:01:30,730
So this is the art of stuff, I'll clean this up and I'll clean the task creation as well as starting

20
00:01:30,730 --> 00:01:31,370
the scheduler.

21
00:01:31,680 --> 00:01:33,280
So our main function is empty.

22
00:01:34,080 --> 00:01:37,620
I would delete the task functions as well or delete this.

23
00:01:39,480 --> 00:01:50,340
Or delete this and delete this and actually this, you got the code we have for our you to driver.

24
00:01:51,280 --> 00:01:58,780
I'm going to take that and put it in its own file, so I'm going to come over here, you know, a source

25
00:01:58,780 --> 00:02:02,820
for the right click or send you file over here.

26
00:02:03,970 --> 00:02:06,530
I can see his horse fall and then I'll give it a name.

27
00:02:07,150 --> 00:02:08,710
You ought to see.

28
00:02:10,020 --> 00:02:11,430
And then finish.

29
00:02:14,720 --> 00:02:21,980
OK, and then include over here, I'll create the dot h version of this dot c file I've just created

30
00:02:22,250 --> 00:02:29,400
and I include for the right click Noufal I can select to follow simply C file or C file.

31
00:02:29,510 --> 00:02:30,170
It's fine.

32
00:02:30,470 --> 00:02:33,800
I'll see you at Dorridge and finish.

33
00:02:35,010 --> 00:02:41,160
Also, we're going to include we're going to include an ATC driver, as well as extend or interrupt

34
00:02:41,160 --> 00:02:42,760
to include those folks as well.

35
00:02:44,490 --> 00:02:52,020
But before we created a new force, less populated the folks we currently have to, I'm going to prevent

36
00:02:52,020 --> 00:03:03,300
multiple inclusion by doing if in-depth on a score you add on a school age, if not defined, then we

37
00:03:03,300 --> 00:03:05,490
want to define you at that age.

38
00:03:08,290 --> 00:03:16,160
Then we see and if over here, OK, so let's go to our you ought to see fault.

39
00:03:16,540 --> 00:03:23,070
We're going to start off by including our that each fall so that we have access to our esteemed 32 hull

40
00:03:23,080 --> 00:03:23,650
drivers.

41
00:03:24,130 --> 00:03:30,340
Once that is done, I'm going to go to I may not see fog over here and cut all the code we have for

42
00:03:30,340 --> 00:03:30,550
you.

43
00:03:31,540 --> 00:03:34,510
So this code here is how are you are in it function?

44
00:03:36,640 --> 00:03:37,840
I'm going to cut it.

45
00:03:44,600 --> 00:03:46,120
And then paste over here.

46
00:03:48,490 --> 00:03:56,530
Contrary to paste, then I'm going to rename this, I'm going to remove the static from here and then

47
00:03:57,220 --> 00:04:01,420
I'll just call this new ATX because we're going to have another version.

48
00:04:01,660 --> 00:04:05,140
So I say you are in it for transmuting.

49
00:04:05,140 --> 00:04:07,630
You are is a transmitter in this configuration.

50
00:04:08,320 --> 00:04:11,230
OK, I'm going to go back to I may not see for.

51
00:04:12,170 --> 00:04:12,650
Then.

52
00:04:13,620 --> 00:04:16,290
We have our you ultraright function somewhere.

53
00:04:17,900 --> 00:04:19,610
This is how you try to function.

54
00:04:20,490 --> 00:04:22,950
We know this function, it is currently commented out.

55
00:04:23,790 --> 00:04:26,040
We need it so cuts this.

56
00:04:26,980 --> 00:04:34,390
Come to our you at that see for the hour you are at right function over here and we have to remove the

57
00:04:34,390 --> 00:04:40,120
comments, select or price control, and then and then the comments are removed.

58
00:04:40,750 --> 00:04:43,110
OK, once that is done, we're going to come over here.

59
00:04:43,150 --> 00:04:44,080
Our future.

60
00:04:45,930 --> 00:04:52,440
This one here, so we updated this function to use our you ultraright function, OK?

61
00:04:54,830 --> 00:04:56,390
So I'll cut this.

62
00:04:59,620 --> 00:05:02,380
And I'm going to put this over here like this.

63
00:05:05,410 --> 00:05:14,110
And I'm going to delete this this the one we use in you out right function, OK, so I'm going to copy

64
00:05:14,110 --> 00:05:16,000
this and put out a top here.

65
00:05:22,570 --> 00:05:30,790
OK, and then this is how you are function dysfunction here called error handler doesn't exist in our

66
00:05:30,790 --> 00:05:32,320
new you are to see function.

67
00:05:33,380 --> 00:05:35,940
This handler is defined over here.

68
00:05:36,550 --> 00:05:38,480
Actually, I'm going to delete these.

69
00:05:40,300 --> 00:05:41,070
Items.

70
00:05:41,110 --> 00:05:48,790
This is all me, NFL, I'm going to simplify it, our error handler, we know we're not in implementation

71
00:05:48,790 --> 00:05:49,800
for error or handler.

72
00:05:49,810 --> 00:05:54,580
We can leave it as it is in our mind, Ötzi, but that is not required in our UAT.

73
00:05:55,000 --> 00:05:59,350
So what I'm going to do is you see this line or you are in it.

74
00:05:59,830 --> 00:06:03,370
We can just initialize it without checking for errors or copy this.

75
00:06:04,270 --> 00:06:04,810
And then.

76
00:06:07,280 --> 00:06:10,490
I would just say, or I can leave this and see how you at.

77
00:06:11,530 --> 00:06:19,960
In it, if this is not equal to OK, do nothing, just keep this condition open like this, because

78
00:06:19,960 --> 00:06:24,610
we don't have our hero, everyone laugh out here and we need not bring it because we've not written

79
00:06:24,610 --> 00:06:26,200
any code to handle error.

80
00:06:26,850 --> 00:06:29,760
OK, so this is our you in it.

81
00:06:30,460 --> 00:06:35,770
Next, we're going to configure our UAT for reception.

82
00:06:36,820 --> 00:06:40,410
So this configuration, of course, uses the whole library.

83
00:06:40,540 --> 00:06:49,870
We use the whole library to configure our you at four for Recept for T this one actually has the XRX,

84
00:06:49,870 --> 00:06:51,600
the modest XRX.

85
00:06:52,300 --> 00:07:02,890
OK, so to configure the UAT for IREX, we can just copy this function and then change mode irex to

86
00:07:02,980 --> 00:07:06,790
T only or to IREX only if we are doing IREX.

87
00:07:10,040 --> 00:07:13,460
OK, so this was created in Cuba Kubrick's.

88
00:07:14,590 --> 00:07:22,780
OK, to make the correct version, first of all, I'm going to change the mood here from TXI Rex to

89
00:07:22,780 --> 00:07:24,010
just tax only.

90
00:07:31,660 --> 00:07:34,990
To make the other version, I can simply copy this.

91
00:07:36,630 --> 00:07:46,180
And then there's this over here and change the mood over here, quote, I simply change it to IREX.

92
00:07:47,390 --> 00:07:54,530
Such that this becomes IREX here and I'm going to delete the word imex from it, from both functions.

93
00:07:57,170 --> 00:08:03,230
So we have the talks, if we want to initialize the you attach a transmitter only we use this when I

94
00:08:03,230 --> 00:08:06,020
initialize it as a receiver only we use this.

95
00:08:07,200 --> 00:08:11,580
OK, so once that is done, we move ahead.

96
00:08:13,060 --> 00:08:20,800
To deal with the 80s, so this hour, Ewart's or you autocephaly, we have to expose our Ewart's functions

97
00:08:20,980 --> 00:08:24,400
so that we can access them in our main NFR.

98
00:08:25,960 --> 00:08:30,090
OK, so I'll copy this function prototype copy come to you.

99
00:08:30,100 --> 00:08:35,950
Ordered each file pasted over here and then I'll do the same for the text version.

100
00:08:37,820 --> 00:08:38,640
A copy of this.

101
00:08:41,130 --> 00:08:42,620
And then paste this over here.

102
00:08:46,040 --> 00:08:57,280
OK, so now I can come to I may not see fall and say include you, Outteridge, I say include you at

103
00:08:57,350 --> 00:08:57,800
what age?

104
00:08:59,610 --> 00:09:08,520
And one last thing we forgot to declare our you are Tando typedef, so this Hando typedef we've got

105
00:09:08,520 --> 00:09:10,800
to cut this and take it all.

106
00:09:10,800 --> 00:09:13,860
You ordered Cifas pasted over here.

107
00:09:16,280 --> 00:09:20,420
OK, right, so this is where we have.

108
00:09:24,730 --> 00:09:29,500
Let's build and see what we have control as to save a click over here.

109
00:09:30,940 --> 00:09:31,960
The old project.

110
00:09:33,290 --> 00:09:33,920
Like this.

111
00:09:36,010 --> 00:09:36,500
OK.

112
00:09:36,520 --> 00:09:41,440
Of course, we have a number of errors because of want you to function is being called over here so

113
00:09:41,440 --> 00:09:46,270
we can delete our Ewart's from here and then our Ewart's function.

114
00:09:47,500 --> 00:09:52,590
This one here is to us, you ought to in it as well.

115
00:09:53,080 --> 00:09:58,030
We we've been using all the time, but we've changed a name and we've changed its location.

116
00:09:58,360 --> 00:10:00,030
So I'm going to call it a new function here.

117
00:10:00,040 --> 00:10:05,920
You ought to underscore, you use that to underscore you atkeson it as buttinsky.

118
00:10:08,070 --> 00:10:09,040
It looks good now.

119
00:10:09,780 --> 00:10:11,910
So now let's deal with the ADC.

120
00:10:14,250 --> 00:10:16,920
We're going to come over here to our source for the.

121
00:10:18,170 --> 00:10:25,130
And then create a new far right click you for I call this ADC Dot, see?

122
00:10:26,850 --> 00:10:31,280
Then I'll come over here to include fuda Greta Neuffer.

123
00:10:32,130 --> 00:10:38,970
You selected a file here so that it would type, if not defined, defined for us automatically.

124
00:10:39,390 --> 00:10:40,950
So I'll give it a name, ADC.

125
00:10:42,000 --> 00:10:42,390
Today.

126
00:10:47,000 --> 00:10:49,070
OK, so there's the format it uses.

127
00:10:50,500 --> 00:10:51,030
OK.

128
00:10:53,480 --> 00:11:01,910
So we're going to write a function to enable our ADC, enable a single channel, now ADC and then another

129
00:11:01,910 --> 00:11:04,740
function to reach the ADC data.

130
00:11:05,600 --> 00:11:11,510
So that is what we're going to do and we're going to be using this to run some of our experiment to

131
00:11:11,510 --> 00:11:13,820
understand how things work more deeply.

132
00:11:17,490 --> 00:11:18,960
So inside our.

133
00:11:20,230 --> 00:11:28,380
ABC, that's how far we can include our ADC is going to use bedmate or code, but we can include how

134
00:11:28,390 --> 00:11:34,330
that each course, how that each has our estimate added to F4 Eckstut each.

135
00:11:34,600 --> 00:11:37,540
We don't need to how far this year, but we can include it anyway.

136
00:11:38,390 --> 00:11:44,110
OK, so over here, I'm taking this as an opportunity to show you how we can write to the driver without

137
00:11:44,110 --> 00:11:44,890
using hard.

138
00:11:45,320 --> 00:11:50,050
Of course, those of you who are familiar with my course, you know, I have numerous courses teach

139
00:11:50,050 --> 00:11:52,420
and that always writing drivers from scratch.

140
00:11:52,930 --> 00:11:57,370
Anyway, we're going to have this function here called ADC and it's OK.

141
00:11:57,940 --> 00:12:07,000
And we're going to go to the reference manual and find out how we would be able to initialize the ADC.

142
00:12:07,600 --> 00:12:15,490
So we know the ADC is a peripheral and the ADC converts analog signal to digital for us.

143
00:12:15,970 --> 00:12:20,650
So we have a sensor and we have to attach it somewhere on our MCU.

144
00:12:21,040 --> 00:12:26,110
And then the data that is read by the sensor is brought into the MCU.

145
00:12:26,110 --> 00:12:27,730
So we have to attach it to a pin.

146
00:12:27,860 --> 00:12:28,690
Because of this.

147
00:12:28,960 --> 00:12:35,050
The ADC has channels, these channels are normal, GPA, your pins, but if you want to use them as

148
00:12:35,050 --> 00:12:38,440
ADC pins, you've got to configure them to work as ADC pins.

149
00:12:39,010 --> 00:12:47,440
OK, so in in our UMCOR tax system or in modern day microcontrollers, before we use any module, we

150
00:12:47,440 --> 00:12:50,290
need to enable clock access to that module.

151
00:12:51,680 --> 00:12:59,130
So what I mean by modulus in in a peripheral so the GPA is a peripheral ADC disappear for you, what

152
00:12:59,150 --> 00:13:02,600
is a peripheral spy?

153
00:13:02,600 --> 00:13:03,410
Just a peripheral.

154
00:13:03,980 --> 00:13:07,660
Before we use any of these peripherals, we need to enable the clock access to them.

155
00:13:08,150 --> 00:13:12,410
So to find the information out how the buzz of the.

156
00:13:13,670 --> 00:13:21,110
Microcontroller is connected, we have to go to the datasheet document, so this document here, you

157
00:13:21,110 --> 00:13:23,030
can search it on the Internet.

158
00:13:25,730 --> 00:13:32,060
This is the datasheet one hundred and forty nine pages, you can simply such as the M 32 F or one one

159
00:13:32,060 --> 00:13:39,230
datasheet in a way, this block diagram here in the datasheet, the document ptosis.

160
00:13:40,850 --> 00:13:42,230
Oh, things are connected.

161
00:13:43,820 --> 00:13:49,540
This block diagram shows the buses and as you can see, there are two types of buses.

162
00:13:50,300 --> 00:13:52,040
We have the bus.

163
00:13:54,960 --> 00:14:01,770
And HP stands for advanced high performance busts, and then we have the APB bus, which stands for

164
00:14:01,770 --> 00:14:02,990
Advanced Peripheral Bus.

165
00:14:03,540 --> 00:14:13,140
So HP, we have HP, one HP to HP, one APB to what I mean by APB is this bus over here.

166
00:14:13,770 --> 00:14:14,220
Right.

167
00:14:15,000 --> 00:14:19,970
So we have to know which of the buses is connected to the patrol we are interested in.

168
00:14:20,360 --> 00:14:26,790
We are interested in you as well because we said our ATC has channels and these channels I just G.P.A.

169
00:14:27,120 --> 00:14:28,380
where we connect our senses.

170
00:14:29,100 --> 00:14:31,950
So in this example, we're going to use a one.

171
00:14:33,310 --> 00:14:39,070
So we're going to use you put a pin one, so because of that, we would need to enable clock access

172
00:14:39,070 --> 00:14:39,970
to your ports.

173
00:14:39,970 --> 00:14:47,140
A as we can see over here, you put a has this arrow connect to it and then connect into this bus with

174
00:14:47,140 --> 00:14:51,220
a name h.b one to then to enable to use GPS.

175
00:14:51,660 --> 00:14:58,030
We need to enable clock access to it and to enable clock access to tell you if we need to go through

176
00:14:58,030 --> 00:14:59,780
the AHP one bus.

177
00:15:00,640 --> 00:15:06,580
So then what we have to do is go to the AHP one module and find a register that allows us to edit to

178
00:15:06,580 --> 00:15:11,760
enable clock access to all the peripherals connected to the HP one bus.

179
00:15:12,100 --> 00:15:13,420
That is what we shall do next.

180
00:15:13,900 --> 00:15:17,130
Before we leave, we have to enable the ATCs well.

181
00:15:17,440 --> 00:15:18,280
So let's see.

182
00:15:19,390 --> 00:15:21,700
Which bus the ADC is connected to?

183
00:15:22,820 --> 00:15:24,020
Where is this is the.

184
00:15:24,620 --> 00:15:32,030
So this is ADC one or microcontroller has a single ADC, this is ADC one and we find an arrow touchin

185
00:15:32,030 --> 00:15:34,790
ADC one and then connecting to APV two.

186
00:15:35,810 --> 00:15:42,470
So meaning to enable access to ADC one, we have to go through the APB to bus.

187
00:15:43,070 --> 00:15:51,630
And what that means is we have to go and find out which register in the APB to Range allows us to enable

188
00:15:51,630 --> 00:15:53,830
clock access to ADC.

189
00:15:54,890 --> 00:15:55,340
OK.

190
00:15:56,790 --> 00:16:01,380
So to find the registers, we need a separate document known as the reference manual.

191
00:16:02,280 --> 00:16:06,360
This document is called R.M. zero three eight three.

192
00:16:06,370 --> 00:16:09,450
So you can simply search SDM 32 hour and.

193
00:16:10,640 --> 00:16:15,950
Zero three eight three on Google and you get a reference manual for the three to for one one.

194
00:16:17,610 --> 00:16:20,380
Microcontroller Ariff stands for Reference Manual.

195
00:16:20,640 --> 00:16:22,360
So this has over 800 pages.

196
00:16:22,380 --> 00:16:24,870
Obviously, we're not meant to read all at once.

197
00:16:24,870 --> 00:16:30,450
It's for reference to the reference we are looking for as the we said, HP.

198
00:16:31,170 --> 00:16:32,880
So I'm going to come over here.

199
00:16:32,910 --> 00:16:36,990
I'll do control F and then type the HP one.

200
00:16:37,120 --> 00:16:45,170
That is where we saw our that is where we saw our connected HP one, HP one over here.

201
00:16:45,180 --> 00:16:47,130
This is it is connected.

202
00:16:48,810 --> 00:16:51,180
So I'm going to switch HP one.

203
00:16:52,770 --> 00:16:59,670
And over here, it brings us to a number of registers, there is h.b, one pair, four resets register.

204
00:16:59,940 --> 00:17:03,720
OK, let's scroll down and see what other registers we have.

205
00:17:04,050 --> 00:17:07,350
There is the H.B, one pair, four o'clock and they will register.

206
00:17:07,380 --> 00:17:09,020
This sounds like what we are interested in.

207
00:17:09,330 --> 00:17:13,680
So we click on this and when we come over here, it tells us.

208
00:17:14,660 --> 00:17:22,240
The meaning of each bit in the register over here beats zero in this register stands for you, a enable

209
00:17:22,260 --> 00:17:26,000
which one is for GPA would enable it to is for GPA.

210
00:17:26,000 --> 00:17:26,390
You see a.

211
00:17:27,020 --> 00:17:32,660
And what this means is we can go to zero and read what it means by scrolling down here.

212
00:17:33,700 --> 00:17:38,760
We have explanation for what zero is it says Jhpiego, and.

213
00:17:39,800 --> 00:17:47,180
I will put a clock enable set and cleared by software, if this is zero, then put a clock is disabled.

214
00:17:47,180 --> 00:17:49,520
If this is one, then put a clock.

215
00:17:49,550 --> 00:17:50,450
This enabled.

216
00:17:51,690 --> 00:17:58,530
So we have two sets, but number one, we have two sets, bitz number zero to one to enable clock access

217
00:17:59,010 --> 00:17:59,780
to Port A.

218
00:18:00,180 --> 00:18:01,170
So that is simple.

219
00:18:03,180 --> 00:18:10,730
It is located in the RCC module and the name of the register is H.B one enabled.

220
00:18:11,250 --> 00:18:13,890
So we can simply do this.

221
00:18:16,450 --> 00:18:25,540
We say RACC module and then h.b one enable, you see, it's a structure, we've even found it h.b one

222
00:18:25,540 --> 00:18:34,330
enable register and then we say equal to we want to set bitz number zero to one so we can simply say

223
00:18:34,330 --> 00:18:39,640
one because one is the same as one in binary.

224
00:18:41,270 --> 00:18:49,040
Or we can see a shift, we can say shift one.

225
00:18:51,530 --> 00:18:56,990
To better position zero, and this implies that this implies that.

226
00:18:58,080 --> 00:19:08,190
This implies that we're going to we're going to shift one the value or the number one to position zero

227
00:19:08,190 --> 00:19:10,690
of this 32 bit register.

228
00:19:11,220 --> 00:19:12,450
So that is what we're doing here.

229
00:19:12,960 --> 00:19:25,590
Or we can simply write one because one here is the same as one is the same as writing a decimal zero

230
00:19:25,590 --> 00:19:33,210
zero zero zero zero zero one one two three four five six seven seven zeros is the same as writing this.

231
00:19:33,540 --> 00:19:43,020
If we convert this hexadecimal zero zero one to binary, what we would have is zero B for binary notation

232
00:19:43,020 --> 00:19:50,400
and then zero zero zero zero zero zero zero zero all the way here to one such that we would have thirty

233
00:19:50,430 --> 00:19:51,420
one zeros here.

234
00:19:52,450 --> 00:19:57,220
All the way to one, and this is the same as one in decimal.

235
00:19:58,430 --> 00:20:06,860
OK, so we can we can write it in hexadecimal notation or we can simply write this one, or we can see

236
00:20:07,400 --> 00:20:09,710
shift to one two position zero.

237
00:20:11,450 --> 00:20:17,210
OK, so remember, let me arrange this for you.

238
00:20:17,420 --> 00:20:20,210
I mean, if I'm doing this, I have to do it properly.

239
00:20:24,350 --> 00:20:26,000
For those of you who are not aware.

240
00:20:27,540 --> 00:20:31,860
For binary digits, give us one hexadecimal digit.

241
00:20:34,160 --> 00:20:40,100
So that is why we have eight digits here, one, two, three, four, five, six, seven, and actually

242
00:20:40,100 --> 00:20:41,000
there should be a last one.

243
00:20:42,260 --> 00:20:47,460
So one, two, three, four, five, six, seven, eight.

244
00:20:48,080 --> 00:20:55,040
So this zero will give us four binary zeros, the second zero for binary zeros, the third zero, and

245
00:20:55,040 --> 00:21:00,260
then all four binary zeros onto the last one will give us zero zero zero one.

246
00:21:01,610 --> 00:21:02,970
And this equals one.

247
00:21:04,070 --> 00:21:10,010
So, in effect, I can simply just write one here, right?

248
00:21:10,070 --> 00:21:14,840
This is not about ARTUS, but I cannot just drop it here without elaborating.

249
00:21:15,140 --> 00:21:20,090
OK, so next, we saw this and.

250
00:21:22,610 --> 00:21:31,880
We also saw that our ATC module is connected to the APB to us, we can verify that we can go back there

251
00:21:31,880 --> 00:21:36,560
and confirm ATC here is connected to APB to bus.

252
00:21:36,750 --> 00:21:46,070
So let's find the APB to powerful and they will register in our reference manual or come up here.

253
00:21:48,410 --> 00:21:51,650
And then I'll do the same thing, control f EPB to.

254
00:21:56,550 --> 00:21:59,440
And then there is APB to Perry for a neighborhood register.

255
00:21:59,580 --> 00:22:00,480
I'm going to click this.

256
00:22:03,230 --> 00:22:03,800
OK.

257
00:22:06,470 --> 00:22:07,160
Liversidge.

258
00:22:10,250 --> 00:22:11,530
APB, too.

259
00:22:12,210 --> 00:22:14,610
OK, I clicked on H.B, rather.

260
00:22:14,660 --> 00:22:16,760
OK, so let's scroll down and find APV.

261
00:22:17,480 --> 00:22:18,680
This is AP one.

262
00:22:18,890 --> 00:22:22,730
So AP to should be down here.

263
00:22:28,560 --> 00:22:29,310
Let's see.

264
00:22:33,560 --> 00:22:35,830
This is a screw problem.

265
00:22:39,710 --> 00:22:44,630
OK, this APB, too, and when we check bits, number eight of APB to.

266
00:22:46,140 --> 00:22:47,620
Therefore, enable register.

267
00:22:47,640 --> 00:22:53,940
It is called ADC one end, meaning we need two sets, bitta number eight in the app to register.

268
00:22:55,560 --> 00:23:03,360
To one, in order to enable the ADC so we can come over here and say RACC module.

269
00:23:06,840 --> 00:23:14,910
And then we see a PB to eat and register and we want to shift one.

270
00:23:16,720 --> 00:23:17,810
Two bits, number eight.

271
00:23:19,660 --> 00:23:33,580
So over here, we're doing a neighbor clock for ABC, and then over here we're doing a neighbor clock

272
00:23:34,570 --> 00:23:38,310
for you to be consistent.

273
00:23:38,320 --> 00:23:44,260
I'm going to use this method over here, shift one to position zero.

274
00:23:46,720 --> 00:23:54,330
OK, so over here we have a neighborhood clock access for our ATC module.

275
00:23:54,340 --> 00:23:56,190
And then I want you to put a module.

276
00:23:56,200 --> 00:24:00,640
And the reason we need your report is because you want to use P one as our ADC channel.

277
00:24:01,160 --> 00:24:05,740
Next, we need to go to our Jhpiego section to find out.

278
00:24:05,770 --> 00:24:07,840
OK, I have my Jhpiego.

279
00:24:08,170 --> 00:24:10,470
How do I need them to work as ADC?

280
00:24:10,900 --> 00:24:13,210
How do I set them up as ADC?

281
00:24:13,600 --> 00:24:16,620
So I'm going to set you here in our reference manual.

282
00:24:17,380 --> 00:24:22,470
And then over here we in the U.S., I'm going to go to the registers.

283
00:24:22,480 --> 00:24:24,400
There should be a register set in the mood.

284
00:24:25,000 --> 00:24:27,520
So there is this register called Portmore which register.

285
00:24:27,520 --> 00:24:31,600
I'm going to click over here and Portmore Dredgers that tells us that.

286
00:24:33,620 --> 00:24:43,280
If we want to set a particular pin to analog, OK, first of all, this Portmore Dredges, this 32 bit

287
00:24:43,280 --> 00:24:47,540
register is going to start from zero and it's a 31.

288
00:24:49,740 --> 00:24:54,630
In Portsmouth Register, which is known as the mortgage register or the motor or motor.

289
00:24:55,590 --> 00:24:57,310
Two, it is for one person.

290
00:24:57,330 --> 00:25:04,080
So you see we have more than zero here and then we have more than one would have to move the cirrhotics

291
00:25:04,080 --> 00:25:10,200
bit Zurin one more than one takes between two and three more to two takes between four and five.

292
00:25:10,860 --> 00:25:11,370
OK.

293
00:25:13,060 --> 00:25:20,290
So Malaysia is for all passengers, more than one is for open ones, all the way to more than 15 for

294
00:25:20,320 --> 00:25:21,360
all furphies.

295
00:25:21,820 --> 00:25:26,770
So we are interested in pay one so there will be more than one.

296
00:25:27,520 --> 00:25:32,550
So then we are dealing with between two and three of the mobile register.

297
00:25:33,010 --> 00:25:38,770
So bid two and three have to be one and one before we can set up one.

298
00:25:39,990 --> 00:25:45,930
As analog to setup one US analog, we have to set it two and three to one in one.

299
00:25:47,390 --> 00:25:47,870
OK.

300
00:25:49,730 --> 00:25:54,230
So that is what we're going to do next to one in one here.

301
00:25:54,260 --> 00:25:55,340
What does that imply?

302
00:25:56,670 --> 00:25:58,620
We can convert this into.

303
00:26:01,100 --> 00:26:08,270
We can convert this into hexadecimal notation and we realized that we would end up with zero zero one

304
00:26:08,270 --> 00:26:11,780
one zero zero one one is the same as XY.

305
00:26:13,060 --> 00:26:15,730
Zero zero one one in binary issue XY.

306
00:26:16,720 --> 00:26:17,260
OK.

307
00:26:19,620 --> 00:26:26,330
But we're not going to ride the seat, so I'm going to come over here and then I'm going to say, you

308
00:26:26,610 --> 00:26:35,910
remember to know what I type in the in the document is the name you were dealing with POTTY, and then

309
00:26:35,930 --> 00:26:37,160
is the name of the register.

310
00:26:37,170 --> 00:26:40,040
So it stands for the GPL airport.

311
00:26:40,050 --> 00:26:45,360
So I simply typed you bought a and then.

312
00:26:46,260 --> 00:26:48,390
Motor register like this.

313
00:26:50,920 --> 00:26:55,360
And then I can simply set this by saying EXI.

314
00:26:57,290 --> 00:27:03,080
And if I expand, as you see this hexadecimal number, if I expand it to binary, I'm going to.

315
00:27:04,980 --> 00:27:08,560
This remember, each hexadecimal number is for binary bits.

316
00:27:08,610 --> 00:27:14,870
This is the same as one one 00 and this corresponds to bits number two and bits number three.

317
00:27:15,210 --> 00:27:17,990
And we know bits number two and three other bits.

318
00:27:18,000 --> 00:27:21,180
We need two sets, one, one Kozmo.

319
00:27:21,180 --> 00:27:22,680
That one is for P one.

320
00:27:22,680 --> 00:27:28,260
It's number two and three need to be set to one one to get this analogue pin.

321
00:27:30,140 --> 00:27:32,600
OK, so this means.

322
00:27:37,090 --> 00:27:39,520
So it's one less analog.

323
00:27:43,750 --> 00:27:48,810
Of course, you can use this method, you can use this method by shifting as well.

324
00:27:49,330 --> 00:27:56,430
And also one other thing you see over here, what I'm doing is I'm simply assigning values to the register.

325
00:27:57,310 --> 00:27:59,400
I'm simply assigning values to the register.

326
00:27:59,590 --> 00:28:04,230
Mean in the end, the entire 32 bit register is cleaned.

327
00:28:04,240 --> 00:28:08,260
And this new value that I'm assigning becomes the new value of the register.

328
00:28:08,710 --> 00:28:11,650
A better way to do with this is to use the operation.

329
00:28:12,680 --> 00:28:17,070
When we do this, only the bits that we want to change will change.

330
00:28:17,300 --> 00:28:22,070
So in this case, only bits number eight is going to be said to one and only bits.

331
00:28:22,070 --> 00:28:28,020
Number zero is going to be said to one in this register and all other bits would have the original value.

332
00:28:28,280 --> 00:28:29,930
I can do the same for this.

333
00:28:31,730 --> 00:28:40,490
OK, so once we've done this, the next thing we do is simply enable the ATC over here, I'm not going

334
00:28:40,490 --> 00:28:42,460
to go through the ADC configuration.

335
00:28:42,470 --> 00:28:44,180
That will be an entirely different lesson.

336
00:28:44,190 --> 00:28:46,220
So I'll just bring the configuration code.

337
00:28:46,610 --> 00:28:48,150
So we go to the ADC module.

338
00:28:48,260 --> 00:28:49,430
It's quite a number of registe.

339
00:28:49,430 --> 00:28:56,900
This is called control register to Squaddie Sequencer, Register three sequencer register one.

340
00:28:57,920 --> 00:29:05,000
We go to control register when we set it to zero zero, its main software trigger because our ADC can

341
00:29:05,000 --> 00:29:10,910
have more output, can have different triggers, we can trigger it using other sources to see the standard

342
00:29:10,910 --> 00:29:13,790
trigger, which is the software itself.

343
00:29:13,790 --> 00:29:20,510
Some the ADC data we just set, we just write zero to control register two and you can go to the reference

344
00:29:20,510 --> 00:29:21,650
minor if interested.

345
00:29:22,790 --> 00:29:29,150
You can go to the section on ADC and read about ADC one underscore.

346
00:29:29,150 --> 00:29:30,050
See our two.

347
00:29:31,640 --> 00:29:37,340
And then over here, conversion is going to start at Channel One, we have a single channel and then

348
00:29:37,340 --> 00:29:40,700
the conversion land, we have to decide what is the conversion then.

349
00:29:41,030 --> 00:29:46,270
If we had multiple channels and we wanted to sample more, we would increase the conversion rate.

350
00:29:46,280 --> 00:29:53,270
But we set it to zero over here because we have just a single conversion and then we enable the ADC

351
00:29:53,270 --> 00:30:00,920
by writing one to the control register to OK, if you want to learn how to write or code for all peripherals,

352
00:30:00,920 --> 00:30:05,810
not just the ADC, you can take a look at my embedded systems permit or programming course.

353
00:30:06,500 --> 00:30:09,760
Right, if we are to spend time going deeper into this.

354
00:30:10,310 --> 00:30:11,990
This course won't end today.

355
00:30:14,740 --> 00:30:21,880
OK, so next, we'll write a function to read the ADC data, so dysfunctional, right, or retender

356
00:30:21,880 --> 00:30:29,750
data so it will return to you and 32 unaskable tea in the name of the function will be read analogue.

357
00:30:29,890 --> 00:30:34,780
And so takes no argument like this.

358
00:30:36,070 --> 00:30:39,910
And what we have to do here is first to start the ADC conversion.

359
00:30:39,910 --> 00:30:43,980
We said software trigger, so we have to start the ADC conversion to do this.

360
00:30:44,470 --> 00:30:46,240
OK, this one I would explain.

361
00:30:46,750 --> 00:30:50,770
We're going to go to the ADC, part of the reference manual.

362
00:30:51,190 --> 00:30:58,720
I'll come up here and control F and then I'll search ADC and I'll scroll down to ADC Registers.

363
00:31:01,520 --> 00:31:02,630
OK, and then.

364
00:31:03,830 --> 00:31:05,920
Still scrolling on a stop scrolling.

365
00:31:09,350 --> 00:31:16,580
And then we're going to go to the ATCC ata, which is ADC Control Register to remember we said.

366
00:31:17,520 --> 00:31:21,210
When we said control register two for software trigger.

367
00:31:22,420 --> 00:31:28,120
When we write zero, it gives off to a trigger because zero basically sets the entire register.

368
00:31:29,640 --> 00:31:33,150
To zero and including the bit has to decide.

369
00:31:34,030 --> 00:31:43,630
Which triggered the ADC should use OK, so bits number 30 here, let's see bits, number 30, S.W. starts.

370
00:31:44,970 --> 00:31:53,130
It's no 30 years code start conversion of regular channels, so we have to set bit number 30 to one

371
00:31:53,700 --> 00:31:56,040
to start conversion on our ADC.

372
00:31:59,080 --> 00:32:06,630
OK, and then once we started conversion, we have to wait for the conversion to be complete.

373
00:32:07,840 --> 00:32:12,160
So I'm going to come over here the first and we're going to do is this one.

374
00:32:13,180 --> 00:32:21,790
We're going to access the control register two and then we're going to see the operator because we want

375
00:32:21,790 --> 00:32:22,690
to change only bits.

376
00:32:22,690 --> 00:32:27,520
Number 30, we're going to say shift one to bits, number 30.

377
00:32:29,620 --> 00:32:30,530
And David.

378
00:32:32,390 --> 00:32:34,040
Start easy conversion.

379
00:32:37,560 --> 00:32:44,790
Once that is done, we have to wait for conversion and when conversion is complete, we would know this

380
00:32:45,270 --> 00:32:51,600
from the status register of the ADC so we can know whether the conversion was completed or not.

381
00:32:52,510 --> 00:33:00,190
By checking a particular bit in the ATC status register, so let's find that so does the register.

382
00:33:00,220 --> 00:33:01,600
It's called the ATC.

383
00:33:01,600 --> 00:33:05,230
Underscore our ATC status register over here.

384
00:33:05,230 --> 00:33:09,090
There's a bit called EEOC, meaning end of conversion bits, number one.

385
00:33:09,640 --> 00:33:12,550
So it says regular channel and of conversion.

386
00:33:12,550 --> 00:33:15,540
This bit is set by the hardware at the end of the conversion.

387
00:33:16,000 --> 00:33:22,840
So we have to check if this bit is set and if it sets, it will let us know that all conversion has

388
00:33:22,840 --> 00:33:24,490
ended its bid to number one.

389
00:33:24,820 --> 00:33:29,500
So what we want to do is come over here and see one

390
00:33:32,140 --> 00:33:39,970
ADC, one status register, and then we perform on an operation of this.

391
00:33:40,480 --> 00:33:49,600
And the number two, the number two, because two is the same as binary notation.

392
00:33:52,300 --> 00:33:56,630
Zero one like this, so this is bits number zero.

393
00:33:56,650 --> 00:34:00,850
This is bit number one, this in decimal notation equals two.

394
00:34:01,510 --> 00:34:08,760
So we can simply say ADC one as and number two like this and we're performing an end operation.

395
00:34:09,040 --> 00:34:19,030
OK, so we say if we perform this operation and it's forced this this will indicate that our bitz number

396
00:34:19,030 --> 00:34:19,810
one is not set.

397
00:34:19,810 --> 00:34:21,640
If it was, then we will get stuck here.

398
00:34:22,240 --> 00:34:26,500
So essentially what we are doing is waiting for conversion.

399
00:34:32,370 --> 00:34:39,990
To complete and watch the conversion is complete, we would return our function is supposed to return

400
00:34:39,990 --> 00:34:40,690
you into that.

401
00:34:40,710 --> 00:34:47,570
To underscore t so the sense of value is going to be stored in the ADC data register.

402
00:34:47,580 --> 00:34:55,230
So ADC one, D-R will just return this register and return the content essentially.

403
00:34:58,490 --> 00:35:00,740
And what we are doing has returned results.

404
00:35:02,820 --> 00:35:14,790
OK, so this is it, we have our ADC functions, we have it easy in it and read analog signs or so I'll

405
00:35:14,790 --> 00:35:20,100
copy this and take it to our ADC to each file so that we can have access to these functions.

406
00:35:20,100 --> 00:35:21,050
And I may not see.

407
00:35:22,050 --> 00:35:23,390
And then I'll copy this as well.

408
00:35:26,420 --> 00:35:29,170
And then pull this over here, OK?

409
00:35:31,050 --> 00:35:38,850
So in the next lesson, we shall deal with our external interrupt driver, so that's all there is and

410
00:35:38,850 --> 00:35:39,510
I'll see you later.

411
00:35:39,510 --> 00:35:42,500
If you have any questions, leave them in the questions and this area of.
