1
00:00:00,580 --> 00:00:00,950
Hello.

2
00:00:00,970 --> 00:00:01,540
Welcome back.

3
00:00:01,540 --> 00:00:10,000
In this lesson we shall see how to configure a y GPA port on the Texas Instrument team 4C 1 2 3 microcontroller

4
00:00:10,030 --> 00:00:12,630
using bare metal code.

5
00:00:12,940 --> 00:00:20,630
Come over here to create a new project new project and I'll keep it in a folder I've created quite a

6
00:00:20,650 --> 00:00:21,690
folder here.

7
00:00:28,140 --> 00:00:30,020
Create a new 4.0 Stories Project projects.

8
00:00:30,030 --> 00:00:32,430
I'll call this Kiki Io

9
00:00:38,650 --> 00:00:39,280
output

10
00:00:43,590 --> 00:00:46,110
and I'll call the project to tell you outputs as well.

11
00:00:46,110 --> 00:00:49,010
GPA or score output.

12
00:00:50,290 --> 00:00:53,730
Like this approach I'm going to select my board.

13
00:00:53,740 --> 00:00:56,250
It's the team for you.

14
00:00:56,460 --> 00:00:59,820
1 2 3 zero.

15
00:00:59,840 --> 00:01:01,460
Age 6 p.m..

16
00:01:01,700 --> 00:01:02,350
Like this.

17
00:01:02,420 --> 00:01:05,470
And then I select this then okay.

18
00:01:05,730 --> 00:01:13,100
Then under CMC as I select call on the device I select start up and then okay over here and then I'll

19
00:01:13,100 --> 00:01:20,710
change the target to the name of my MCU team for C 1 2 3 and then over here.

20
00:01:20,710 --> 00:01:27,620
Source group Oh name it I rename it to APB for up and I'll come to target options right here.

21
00:01:27,700 --> 00:01:34,780
I'll say this to my extort which is 16 megahertz debug by here I'll select distilleries ICD I this one

22
00:01:34,780 --> 00:01:40,280
over here and then I'll click over here and I'll take this.

23
00:01:40,310 --> 00:01:48,390
Yeah reset and run and then okay and then OK then I'm going to come over here right click that new item

24
00:01:48,870 --> 00:01:55,790
and then I'll add to demand that c file name over here in the c file.

25
00:01:56,250 --> 00:01:56,970
So right.

26
00:01:57,810 --> 00:02:06,540
So over here in call you vision you can you perform so all you wish and provide just the complete solution

27
00:02:06,630 --> 00:02:13,700
apart from keeping our project well structured and given us the debugger and other things like the compiler.

28
00:02:13,860 --> 00:02:20,100
It also provides us with reference manuals and books when it comes to the books tab whichever microcontroller

29
00:02:20,130 --> 00:02:26,340
they use in call you vision provides the required reference my no audio available reference material

30
00:02:26,610 --> 00:02:33,840
for that particular hardware for instance we've got the TVC Tim 4C One two three data sheet here and

31
00:02:33,840 --> 00:02:39,840
we've got cortex and for generic User Guide this is because the Tim 4C One two three microcontroller

32
00:02:40,170 --> 00:02:47,440
is a cortex M4 and also we've got books here dealing with the compiler as well as cow empty K itself.

33
00:02:47,520 --> 00:02:48,660
So let's click here and see

34
00:02:51,990 --> 00:02:52,590
OK.

35
00:02:52,630 --> 00:02:56,250
It says Page Not Found this shouldn't be what's happening right.

36
00:02:56,290 --> 00:02:59,490
So Texas Instruments has to fix this.

37
00:03:00,340 --> 00:03:06,110
Often when you open here it takes you directly to the link of the PDA off of the data sheet.

38
00:03:06,160 --> 00:03:06,710
Right.

39
00:03:06,730 --> 00:03:11,140
Since the link is broken for this particular M.S. you would have to find it.

40
00:03:11,160 --> 00:03:16,720
So before we program the microcontroller in bare metal we first need to examine how its peripherals

41
00:03:16,720 --> 00:03:24,130
are connected and how its clock is connected to the various components as well as how the registers

42
00:03:24,160 --> 00:03:25,600
are arranged.

43
00:03:25,600 --> 00:03:30,900
So to do that we need to take a look at the data sheet so that is what a microcontroller.

44
00:03:31,060 --> 00:03:33,480
But we have the development board.

45
00:03:33,520 --> 00:03:34,300
Right.

46
00:03:34,330 --> 00:03:40,510
So the development board has the microcontroller on it and it provides us with certain eye or devices

47
00:03:40,540 --> 00:03:42,630
we can experiment with.

48
00:03:42,760 --> 00:03:47,380
We've got OLED here we've got push buttons here and we've got other things.

49
00:03:47,410 --> 00:03:53,320
So let's first take a look at the user guide for the development board so that we know which pins our

50
00:03:53,320 --> 00:03:56,330
LCD and push buttons are connected to.

51
00:03:56,330 --> 00:04:03,790
So then when we go to the data sheet and see how the GPI use connected to the CPE you we know exactly

52
00:04:03,820 --> 00:04:09,630
which PS to initialize in order to control whether LCD or push button.

53
00:04:09,700 --> 00:04:14,580
So I'm going to go to Google over here and I'll see Tim for.

54
00:04:15,190 --> 00:04:17,920
1 2 3 0 c

55
00:04:22,290 --> 00:04:26,090
launch pad and then I'll just I'll just search

56
00:04:30,910 --> 00:04:32,180
or search user guide.

57
00:04:32,190 --> 00:04:35,190
Let's see you guys should give us this.

58
00:04:35,190 --> 00:04:35,550
OK.

59
00:04:35,580 --> 00:04:42,300
So there's a link it TVC series the unforeseen launch part of evaluation kit use a guide right click

60
00:04:42,300 --> 00:04:42,870
this.

61
00:04:42,930 --> 00:04:49,770
So over here the the purpose of this course is not just to give you a cookbook approach such that when

62
00:04:49,770 --> 00:04:55,800
you're looking for this you do this and no the purpose is to make you a better embedded systems developer.

63
00:04:56,190 --> 00:05:01,430
So this assumes this assumes you know you're not familiar with the overseas series at all.

64
00:05:01,680 --> 00:05:02,910
You've just put this board.

65
00:05:03,480 --> 00:05:06,610
And how do you go about to program it.

66
00:05:06,630 --> 00:05:07,720
This is how you program it.

67
00:05:07,730 --> 00:05:11,760
First you take a look at the user guide and you take a look at a data sheet.

68
00:05:11,760 --> 00:05:15,370
Once you've done that you know exactly how to control the board.

69
00:05:15,510 --> 00:05:19,350
And you can apply this to any microcontroller regardless of the vendor.

70
00:05:19,710 --> 00:05:21,930
So that is why I'm taking this approach.

71
00:05:21,930 --> 00:05:25,750
I can write all the code and just tell you do this do that.

72
00:05:25,770 --> 00:05:32,090
So rather than telling you straightforward what needs to be done in this course I'm going to take you

73
00:05:32,090 --> 00:05:36,180
to the data sheet and you and I shall find information together.

74
00:05:36,260 --> 00:05:42,380
We would assume we just got this new microcontroller from Texas Instrument and we are embedded developers

75
00:05:42,410 --> 00:05:46,780
and we want to know how to program this type of microcontroller.

76
00:05:46,790 --> 00:05:52,700
So I'm going to be taking you through the steps that we often go through in order to figure out information

77
00:05:52,700 --> 00:05:58,530
about a new development board or a new microcontroller from a different manufacturer.

78
00:05:58,550 --> 00:05:59,130
Right.

79
00:05:59,150 --> 00:06:06,820
So let's take a look at this user guide so the user guide for our TVC launch part evaluation board.

80
00:06:06,830 --> 00:06:08,900
I'm going to scroll down here.

81
00:06:08,900 --> 00:06:11,420
Over here we have an overview of the board.

82
00:06:11,470 --> 00:06:15,780
It tells us what we've got it says we've got to use a switch over here.

83
00:06:15,780 --> 00:06:17,750
This is quite a use switch too.

84
00:06:17,760 --> 00:06:24,600
We've got one other one here and we've got we've got these bins here.

85
00:06:24,600 --> 00:06:31,160
It's allows us to add something on us booster pack perhaps want to expand this like head pays for I

86
00:06:31,160 --> 00:06:35,640
didn't more just like Bluetooth module Wi-Fi module et cetera.

87
00:06:35,970 --> 00:06:39,190
And we've got our attribute OLED over here as well.

88
00:06:39,360 --> 00:06:45,490
We've got a USB connector in this USP here is for our debugger and it provides post Well there's a post

89
00:06:45,640 --> 00:06:48,240
which this is another microcontroller.

90
00:06:48,240 --> 00:06:51,230
This one is for debugging and this the main microcontroller.

91
00:06:51,300 --> 00:06:56,670
This is where our program is stored right over here.

92
00:06:56,670 --> 00:06:59,200
It took us a bit about it.

93
00:06:59,240 --> 00:07:00,990
You can take a look at it if you prefer.

94
00:07:01,560 --> 00:07:10,140
But what we are truly interested in is the is the schematic diagram to see how the peripherals are connected

95
00:07:10,140 --> 00:07:16,500
to DMC how yeah the for those like the LCD and other things.

96
00:07:16,500 --> 00:07:16,790
OK.

97
00:07:16,800 --> 00:07:18,140
We've got this information here.

98
00:07:18,220 --> 00:07:22,080
User switches and Archie Chibi signals right.

99
00:07:22,080 --> 00:07:28,900
Actually I'm just going to copy all of this controversy to copy and I'm going to bring it over here.

100
00:07:28,920 --> 00:07:30,160
Let's see if it works.

101
00:07:30,330 --> 00:07:30,700
OK.

102
00:07:30,780 --> 00:07:31,530
Excellent.

103
00:07:32,010 --> 00:07:35,460
It's arranged properly so we're going to keep this information here

104
00:07:42,700 --> 00:07:47,930
so we know we've caught our switch one which is on the left.

105
00:07:47,980 --> 00:07:49,880
That's f for window switch to it.

106
00:07:49,900 --> 00:07:58,780
That's PFC you switch P if one has the red LCD and then the blue LCD is SPF 2 3 has the green LCD.

107
00:07:58,810 --> 00:08:00,900
OK good.

108
00:08:00,910 --> 00:08:05,060
So p f just means port F right.

109
00:08:05,090 --> 00:08:07,120
So we've seen this actually.

110
00:08:07,720 --> 00:08:15,070
We have what we need but if you have if you find a user guide and they use a guy doesn't give the table

111
00:08:15,160 --> 00:08:21,940
showing this type of information you often find this in the schematic diagram and over here when you

112
00:08:21,940 --> 00:08:24,430
check the schematic diagram you should see the LCD.

113
00:08:25,270 --> 00:08:26,320
So let's start from the top.

114
00:08:26,320 --> 00:08:27,120
So it is the maze.

115
00:08:27,160 --> 00:08:36,430
This schematic diagram of the main MCU connections and this is the MCU over here from the microcontroller

116
00:08:36,430 --> 00:08:37,070
diagram.

117
00:08:37,090 --> 00:08:40,810
We still see OLED red blue and green here.

118
00:08:41,140 --> 00:08:49,570
So when I assume over here I can see the red is connected to this one here P F one like this when I

119
00:08:49,570 --> 00:08:56,960
trace the wire I realized red SPF 1 and P.F. 2 has blue P 3 has green.

120
00:08:57,120 --> 00:09:03,850
And in fact P A 4 has used a switch one on PSU has used a switch to switch just by seeing this I know

121
00:09:04,530 --> 00:09:07,520
and I can enable it it registers appropriately.

122
00:09:07,750 --> 00:09:14,230
So now that we know where our entities are connected let's go and take a look at the data sheet of a

123
00:09:14,230 --> 00:09:21,910
war with our microcontroller I'm going to come over here and I'm going to search Tim for C 1 2 3 this

124
00:09:21,910 --> 00:09:28,270
time I'll say data sheets and the data sheet is about a chip that microcontroller chip is not about

125
00:09:28,280 --> 00:09:34,850
it TVC development board this is about just the ICI the MCU itself right.

126
00:09:34,960 --> 00:09:36,180
So I'll come over here.

127
00:09:36,190 --> 00:09:38,410
Texas Instruments has a link to it.

128
00:09:38,410 --> 00:09:41,670
I'll click this over here.

129
00:09:41,730 --> 00:09:42,320
Let's see.

130
00:09:42,330 --> 00:09:45,840
It's probably got over a thousand pages often long.

131
00:09:46,950 --> 00:09:47,310
Right.

132
00:09:47,310 --> 00:09:49,680
It's got 1400 pages.

133
00:09:49,680 --> 00:09:50,520
Don't be worried.

134
00:09:50,550 --> 00:09:52,210
You need not read all of it.

135
00:09:52,290 --> 00:09:55,900
In fact you probably use like 20 percent of it.

136
00:09:56,100 --> 00:09:59,270
Most of the time it's just a reference guide.

137
00:09:59,760 --> 00:10:01,570
So this the data sheet is called.

138
00:10:01,590 --> 00:10:06,490
It's table of contents over here and over here starts by saying OK.

139
00:10:06,840 --> 00:10:10,540
Architectural overview the MCU overview etc..

140
00:10:10,680 --> 00:10:12,360
Let's take a look at the MCU.

141
00:10:12,410 --> 00:10:15,750
If you click this and it should have a diagram.

142
00:10:15,880 --> 00:10:16,450
OK.

143
00:10:16,460 --> 00:10:18,560
Excellent square diagram here.

144
00:10:18,570 --> 00:10:24,400
So this did that when we're interested in the first diagram we're interested in this this one this one

145
00:10:25,240 --> 00:10:28,370
tells us which bus are MCU.

146
00:10:28,570 --> 00:10:32,070
Which bus a particular pair four is connected to.

147
00:10:32,370 --> 00:10:37,720
So more than the microcontrollers use two types of buses.

148
00:10:37,750 --> 00:10:44,570
We've got the advanced pair for bus this one here known as the APB assuming a bit and we've got the

149
00:10:44,630 --> 00:10:52,460
advanced height the four months pass known as the HB de HB is extremely fast and with HB you can access

150
00:10:52,460 --> 00:10:59,630
a pair for using a single processor cycle if you want to access a pair full with the APB you may require

151
00:10:59,690 --> 00:11:06,510
at least three processor cycles in order to be able to do that so we have to find the bus our particular

152
00:11:06,580 --> 00:11:14,680
airflow is connected to so that we can enable clock access to the pair flow through the bus so over

153
00:11:14,690 --> 00:11:23,090
here let's see we've got GPA to GPA has an arrow starting from here and over here and it's got an arrow

154
00:11:23,090 --> 00:11:24,620
from here and here as well.

155
00:11:24,770 --> 00:11:34,460
So the GP is are connected both to the HB and the APB so we can control the GPA you or initialize the

156
00:11:34,460 --> 00:11:44,300
GPA you put using the HB bus for the APB bus something like the DMV the DMV also has both HP bus and

157
00:11:44,390 --> 00:11:52,020
APB bus so we can access using both HP and APB that you are is connected just to the APB.

158
00:11:52,350 --> 00:11:58,010
The general purpose time is just to the APB as well in the ATC test to the APD.

159
00:11:58,130 --> 00:11:59,350
Right.

160
00:11:59,360 --> 00:12:00,740
So that's good.

161
00:12:00,740 --> 00:12:04,330
So now we know the bus connection of our GPA.

162
00:12:04,430 --> 00:12:08,920
Let's go to their GP section and see how to configure the GP you.

163
00:12:09,410 --> 00:12:17,450
So I'm gonna scroll back to the table of contents and we're going to go to the GPO side of things which

164
00:12:17,470 --> 00:12:24,250
jump straight to the GP you side going to come back to the top and I'll come down here should be GPA

165
00:12:24,280 --> 00:12:25,700
somewhere down.

166
00:12:26,190 --> 00:12:26,950
Yeah we go.

167
00:12:26,950 --> 00:12:33,280
General Purpose input output so I click over here and this first starts by giving an overview of our

168
00:12:33,280 --> 00:12:34,280
GPO you.

169
00:12:34,360 --> 00:12:42,070
So it says the GPO module is composed of six physical GPO blocks each corresponding to an individual

170
00:12:42,160 --> 00:12:43,240
UK port.

171
00:12:43,240 --> 00:12:52,090
So we've got port a port B port sea port deportee and port f the GPO module supports up to 43 programmable

172
00:12:52,180 --> 00:12:59,960
input output pins depending on the pair for was being use and it goes on to give us the features assess

173
00:13:00,050 --> 00:13:03,500
up to 43 GPL use depending on the configuration.

174
00:13:03,500 --> 00:13:12,320
Highly flexible pin marks in many Multiplex and allows us to use US GPL or several peripheral functions.

175
00:13:12,410 --> 00:13:18,970
This means we can use the same GPL European can be used as a you at a DAC ADC etc..

176
00:13:19,100 --> 00:13:21,730
We'll see how to do all of that and the penis.

177
00:13:21,740 --> 00:13:30,010
Also five fold tolerant and the port are named A2 G and we can access them through the APB bus.

178
00:13:30,080 --> 00:13:32,380
Yeah it's fair to mention the HB here.

179
00:13:32,460 --> 00:13:40,970
Okay it's talking about that here and over here it goes on to tell us that we can access using HB as

180
00:13:40,970 --> 00:13:42,380
well.

181
00:13:42,380 --> 00:13:42,960
Right.

182
00:13:43,010 --> 00:13:50,150
So you can spend some time to read if you're interested in it but we know that we've put a through F.

183
00:13:50,150 --> 00:13:51,470
So that's the take away from here.

184
00:13:51,470 --> 00:13:55,900
We know we've got a through F right to once that is done.

185
00:13:56,000 --> 00:14:04,280
We can go ahead to see if the data sheet tells us how to initialize the GPA to some data sheets go ahead

186
00:14:04,280 --> 00:14:09,460
to give you a step by step information on how to initialize a particular peripheral.

187
00:14:09,500 --> 00:14:12,950
So let's see if this data sheet from Texas Instrument does the same.

188
00:14:13,400 --> 00:14:13,880
OK.

189
00:14:13,880 --> 00:14:17,050
It's called initialization and configuration over here.

190
00:14:17,260 --> 00:14:22,200
And it says the GPA modules may be access to different memory pictures.

191
00:14:22,550 --> 00:14:30,220
The legacy our is the advanced peripheral bus and is backwards compatible with previous devices.

192
00:14:30,350 --> 00:14:37,880
The aperture is the advanced high performance bus and this is just like what we saw in the systems diagram

193
00:14:37,910 --> 00:14:45,290
we saw earlier we saw that the GPA you module is connected both to the AP and the HB.

194
00:14:45,290 --> 00:14:49,990
So we already know this and it's telling us how to decide which one to use here.

195
00:14:50,060 --> 00:14:53,990
It says These are pictures are mutually exclusive.

196
00:14:53,990 --> 00:15:01,980
The aperture the aperture enable for a given GPA port is controlled by the appropriate bits in GPA or

197
00:15:02,090 --> 00:15:04,710
HPC t l register.

198
00:15:04,790 --> 00:15:13,310
So if we want to enable a particular aperture whether APB or HP we would have to enable it using this

199
00:15:13,310 --> 00:15:15,770
register here which we shall take a look at.

200
00:15:16,130 --> 00:15:22,820
But by default we are connected to the APB so if we don't even access this register and we go ahead

201
00:15:23,030 --> 00:15:30,180
to enable our GPA report we will be using the APB but by default unless we want to switch to HB and

202
00:15:30,500 --> 00:15:36,920
over here it gives us steps it says to configure the GPA Europeans for a particular sport follow these

203
00:15:36,980 --> 00:15:37,700
steps.

204
00:15:37,700 --> 00:15:38,550
Right.

205
00:15:38,630 --> 00:15:45,800
First it says we need to enable clock to the port by setting the appropriate bids in the RC GC Can you

206
00:15:45,800 --> 00:15:50,030
register right to a bit of history here.

207
00:15:51,020 --> 00:16:00,260
So in recent years in recent decades I would say microcontroller design has been moving towards low

208
00:16:00,260 --> 00:16:09,230
power systems and previously systems had clog previously microcontroller had clock access to all parts

209
00:16:09,230 --> 00:16:10,730
of it or part of the peripheral.

210
00:16:10,790 --> 00:16:14,060
Regardless of whether you're using it or not.

211
00:16:14,060 --> 00:16:22,250
So this made the the system or the microcontroller consume more power then clock gate in mechanism was

212
00:16:22,250 --> 00:16:29,180
invented and what it clunky to mechanism means is you only enable clock to the part of the MCU that

213
00:16:29,180 --> 00:16:30,910
you want to use.

214
00:16:30,920 --> 00:16:38,180
So with a clock gating mechanism if I'm using just puts a I need to enable clock access just to get

215
00:16:38,240 --> 00:16:46,280
to port a if I'm using just the ADC module I need to enable clock access for just the ADC module I don't

216
00:16:46,370 --> 00:16:53,870
need to enable clock access to every module in the system to save power I just enable clock access to

217
00:16:53,870 --> 00:16:56,820
the peripheral or the module that I'm using.

218
00:16:56,960 --> 00:17:04,640
And over here we use the RC GC GPA you register to do the right thing that stands for propagate and

219
00:17:04,640 --> 00:17:08,000
control register which will see its full name later on.

220
00:17:08,000 --> 00:17:14,060
So that's the that's the reason why we first need to enable that clock by default the various modules

221
00:17:14,330 --> 00:17:17,010
and peripherals do not have clock enabled.

222
00:17:17,060 --> 00:17:18,140
We have to save power.

223
00:17:18,140 --> 00:17:23,420
We cannot be providing clock to each and every corner of the microcontroller so we first need to enable

224
00:17:23,420 --> 00:17:24,300
the clock.

225
00:17:24,320 --> 00:17:30,160
It says over here in addition we've got the SC GC GPL you and DC GC GPL you.

226
00:17:30,170 --> 00:17:34,370
And these are for sleep mode and deep sleep mode right.

227
00:17:34,640 --> 00:17:36,670
So this our first point we need to enable clock.

228
00:17:36,950 --> 00:17:43,910
And then it says set the direction of the GPL your port pin by using the QR code key I are registered.

229
00:17:43,940 --> 00:17:49,610
This is the direction register and this is the register which we use to decide whether our pin is an

230
00:17:49,610 --> 00:17:51,800
input being or an output pin.

231
00:17:52,220 --> 00:18:01,320
After that if we want to use the GPL for alternate functions such as ADC you at DAC SBI A2 C etc..

232
00:18:01,430 --> 00:18:06,860
We've got to configure that alternate function in the GPA to F E L.

233
00:18:06,860 --> 00:18:11,070
This basically means keeping you alternate functions select.

234
00:18:11,240 --> 00:18:17,140
So we've got to configure the automate function in the automate function select register write.

235
00:18:17,210 --> 00:18:24,680
Once that is done if we wish to drive something high current we can use the GPA you drive register so

236
00:18:24,680 --> 00:18:31,070
we've got GPA you d are two are and I think this provides to merely arms or so and this for here stands

237
00:18:31,070 --> 00:18:37,220
for formulae arms and this eight year stands for each of the arms will verify this later but this register

238
00:18:37,250 --> 00:18:46,160
is used to increase the current produce at that particular GPA your PIN and also we can decide to put

239
00:18:46,160 --> 00:18:54,930
a GPA u up or pull it down by initialize and pull up resistor or put our resistor or an open drain resistor.

240
00:18:55,370 --> 00:19:00,980
We can decide to initialize a pull up resistor or pull down or open drain and we've got registers to

241
00:19:00,980 --> 00:19:06,710
allow us to make these elections so these are just optional selection is now first.

242
00:19:06,770 --> 00:19:08,230
The only thing we need to do.

243
00:19:08,230 --> 00:19:14,690
Actually the GPA or module on every microcontroller should have at least two registers the direction

244
00:19:14,690 --> 00:19:20,510
register and the data register after that every other thing is just optional.

245
00:19:20,510 --> 00:19:26,600
But now you can think of the clock gate and register as one of those three compulsory registers.

246
00:19:26,720 --> 00:19:30,000
Because we need to enable clock access to the port.

247
00:19:30,200 --> 00:19:36,310
So once you've got a clock to register and a direction register every other thing should be optional.

248
00:19:36,300 --> 00:19:40,780
Right and we've caught this this at a register.

249
00:19:41,140 --> 00:19:44,000
We leave the rest on we just use them when we required them.

250
00:19:44,710 --> 00:19:47,460
Let's see right.

251
00:19:47,480 --> 00:19:48,130
Right.

252
00:19:48,140 --> 00:19:49,080
Looks good.

253
00:19:49,430 --> 00:19:49,890
OK.

254
00:19:49,910 --> 00:19:53,490
So the table goes on to give us example over here.

255
00:19:53,660 --> 00:20:01,890
For instance if you are initializing a digital input you would want to set the alternate function so

256
00:20:01,890 --> 00:20:04,180
late for that being to zero.

257
00:20:04,290 --> 00:20:06,980
You will set the direction to zero.

258
00:20:07,040 --> 00:20:12,370
You said you already are registered to zero and you set the end to 1 D.

259
00:20:12,390 --> 00:20:14,090
And means digital enabled.

260
00:20:14,090 --> 00:20:20,540
Is that digital enable register and be you are pull up register and put on register you would have to

261
00:20:20,540 --> 00:20:22,450
decide which one you want.

262
00:20:22,520 --> 00:20:24,870
This doesn't apply since it's an input.

263
00:20:25,190 --> 00:20:26,330
So this is just an example.

264
00:20:26,360 --> 00:20:32,870
So that data sheet is a really useful tool for the embedded developer and it's very important that you

265
00:20:32,870 --> 00:20:33,770
get used to it.

266
00:20:33,770 --> 00:20:37,330
You get used to go into the details you to solve your your problems.

267
00:20:37,370 --> 00:20:42,950
It makes you a better programmer when it comes to embedded systems than just looking for you know something

268
00:20:42,950 --> 00:20:43,950
that's already cooked.

269
00:20:43,970 --> 00:20:49,100
And then you just copy and paste or import a library if you want to be good you've got to understand

270
00:20:49,100 --> 00:20:51,800
how to find your way around a data sheet.

271
00:20:52,850 --> 00:20:58,960
So now we have enough information actually to to stop writing code to blink our entity.

272
00:20:59,000 --> 00:21:03,910
So let's go and see how we make use of the information we've got it over here.

273
00:21:03,960 --> 00:21:10,770
I'm back here in Carl vision and this the main file so to include the header file of my microcontroller.

274
00:21:10,780 --> 00:21:16,520
I simply need to right click include file and then I'll select this file is included.

275
00:21:16,540 --> 00:21:26,340
Right so I'm gonna come down here into main to open the main function and open close and I'm going to

276
00:21:26,400 --> 00:21:32,060
open the infinite loop here while one open close as well.

277
00:21:32,220 --> 00:21:33,310
Right.

278
00:21:33,390 --> 00:21:36,340
So let's start by.

279
00:21:36,390 --> 00:21:39,210
So let's start by following the steps we read.

280
00:21:39,210 --> 00:21:43,170
First we need to enable clock access.

281
00:21:43,170 --> 00:21:44,940
Did I close this.

282
00:21:44,940 --> 00:21:45,570
No I didn't.

283
00:21:46,200 --> 00:21:48,030
So we need to enable clock access.

284
00:21:48,030 --> 00:21:51,930
Do not worry we wouldn't be spending so much time in the data sheet.

285
00:21:51,930 --> 00:21:55,320
Well when it's required we would have to find it in the data sheets.

286
00:21:55,320 --> 00:21:59,350
I think it's much more useful this way than me telling you what to write.

287
00:21:59,400 --> 00:22:01,680
So yeah just bear with the process.

288
00:22:01,740 --> 00:22:02,130
Right.

289
00:22:02,670 --> 00:22:05,950
So we would have to enable the clock access.

290
00:22:06,150 --> 00:22:09,550
Let's go and see the RCC register.

291
00:22:09,570 --> 00:22:09,930
Sure.

292
00:22:09,960 --> 00:22:18,670
Come over here you can press control F and search RCC GPO just like we saw in the initialization sequence.

293
00:22:19,620 --> 00:22:23,880
So when you search RCC there's a number of them.

294
00:22:24,420 --> 00:22:28,920
So over here when you actually come down this registers list over here.

295
00:22:28,920 --> 00:22:30,130
Page 18.

296
00:22:30,300 --> 00:22:37,820
And when you come here and you search our CTC your approach is known as the general purpose input outputs

297
00:22:37,830 --> 00:22:41,190
run more run mode clock gate in control.

298
00:22:41,250 --> 00:22:41,670
Right.

299
00:22:41,680 --> 00:22:48,790
And it's under system control over here system control and then there's RC RC GC.

300
00:22:48,870 --> 00:22:50,030
Right.

301
00:22:50,100 --> 00:22:52,290
So let's take a look up this register here.

302
00:22:52,480 --> 00:22:55,140
I'll click on it and I'm brought over here.

303
00:22:55,140 --> 00:23:01,920
This Register says the RC GC GPA register provides software capability to enable and disable GPA your

304
00:23:01,940 --> 00:23:10,050
modules in run mode when enabled and module is provided a clock and accesses to the module register

305
00:23:10,350 --> 00:23:17,620
allowed when disabled the clock is disabled to save power and accesses to the module registers generates

306
00:23:17,690 --> 00:23:18,820
a boss fault.

307
00:23:18,960 --> 00:23:19,350
OK.

308
00:23:19,380 --> 00:23:24,870
So basically we use this to enable clock access for GPL you ports.

309
00:23:24,900 --> 00:23:26,820
So let's take a look at what we've got here.

310
00:23:26,840 --> 00:23:28,570
It's 32 bit.

311
00:23:28,860 --> 00:23:32,100
Starting from Zero over here to 31 over here.

312
00:23:32,100 --> 00:23:34,010
Let's see what 0 is for.

313
00:23:34,020 --> 00:23:35,920
You can find that by coming over here.

314
00:23:36,060 --> 00:23:37,470
So bid 0 over here.

315
00:23:37,470 --> 00:23:42,500
It says it's zero GPA you put a run more clunky and register.

316
00:23:42,810 --> 00:23:46,270
If we set it to zero GPA you put a is disabled.

317
00:23:46,290 --> 00:23:54,850
If we set it to 1 GPA you put a enabled so enable and provide a clock to GPA you put a run mode.

318
00:23:54,900 --> 00:23:55,770
So that's what we do.

319
00:23:55,770 --> 00:24:01,390
We find it under our system control and the name of the register is RC GC GPA.

320
00:24:01,770 --> 00:24:03,270
Right.

321
00:24:03,390 --> 00:24:04,740
So we know how to look at this.

322
00:24:04,740 --> 00:24:06,950
Now let's go and write our code.

323
00:24:07,110 --> 00:24:07,580
Okay.

324
00:24:07,620 --> 00:24:11,570
We are back here in call you vision so to enable clock access.

325
00:24:11,610 --> 00:24:18,050
We simply say CIS control system control and then proceed GC GPA.

326
00:24:18,120 --> 00:24:24,150
Just like we saw in the data sheet and we realised that bit serial corresponds to put a switch to enable

327
00:24:24,150 --> 00:24:33,120
clock access for bit zero for port a we use pid 0 0 ball port f course our entity our entities are connected

328
00:24:33,120 --> 00:24:40,680
to port f let's see Port f I know you can guess where Port F is if zero S is for port eight and you

329
00:24:40,680 --> 00:24:48,360
can tell it up it's five will be four port F can you ever hear better number five is for QPR your port

330
00:24:48,420 --> 00:24:54,930
f run mode clock 18 so it's number five or by here we shall use this to enable clock access to port

331
00:24:54,990 --> 00:25:06,990
F so let's do that now come over here and then I'll do this I'll pass 0 x to zero over here and basically

332
00:25:07,740 --> 00:25:18,960
this is hexadecimal notation I can explain this to binary for you this means 0 0 1 0 and 0 0 0 0 we

333
00:25:18,960 --> 00:25:28,130
can have we can have other 0 0 0 0 0 0 0 but n is you in front of the 2 over here can be deleted cos

334
00:25:28,140 --> 00:25:34,080
he has no effect has I've deleted all of those zeros and I've left this yet but we cannot delete the

335
00:25:34,080 --> 00:25:35,970
zero after that no no.

336
00:25:36,030 --> 00:25:42,030
This affects the bits position so if we check this we know that the euro is for port a the second one

337
00:25:42,030 --> 00:25:49,050
is for Port B puts you port D This one is for Port e and this one about yes for Port f that is why it

338
00:25:49,050 --> 00:25:56,340
is set to 1 and if you compress this into hexadecimal mode it becomes your X to 0 and I'm using this

339
00:25:56,400 --> 00:26:02,820
operator here this is for friendly operation I can disable an equal sign here but when I if I put an

340
00:26:02,880 --> 00:26:09,390
equal sign here what happens is then to our GC GPA you register is going to be written with this new

341
00:26:09,390 --> 00:26:15,840
value so you can think of it this way if a different module lets say a different module using port a

342
00:26:16,200 --> 00:26:23,460
initialized less a better number two or better number three and I come in I initialize use in this statement

343
00:26:23,760 --> 00:26:30,510
I'm going to on initialize what was initialized before because I'm going to set bits number two and

344
00:26:30,510 --> 00:26:32,630
three to zero by writing this to it.

345
00:26:33,150 --> 00:26:40,470
So in order to enable just the bits that I want to be enabled I put the I this Fed school line operation

346
00:26:40,470 --> 00:26:49,560
here operator here such that just this is added just this is added to the the the initial value of the

347
00:26:49,560 --> 00:26:51,590
RC DC GPL you register.

348
00:26:51,750 --> 00:26:52,730
So by doing this.

349
00:26:52,800 --> 00:27:01,740
If the GC GPO register had a value before and it's five over here was it enabled five has just enabled

350
00:27:02,040 --> 00:27:08,310
and all add up bits aren't affected this just makes sure the bit I'm interested in which is bits 5 is

351
00:27:08,310 --> 00:27:09,530
the affected bit.

352
00:27:09,540 --> 00:27:11,670
So this is known as friendly programming.

353
00:27:11,670 --> 00:27:13,050
You put this here like this.

354
00:27:13,430 --> 00:27:16,370
So once we've done this we can set the direction register.

355
00:27:18,000 --> 00:27:23,000
So let's say we want to use the red LRT the red LCD connector to pick F1.

356
00:27:23,130 --> 00:27:31,380
So I'm going to come over here GPA you a direction register SDI R and then I'm going to set its direction

357
00:27:33,240 --> 00:27:35,770
because we want it as output.

358
00:27:36,240 --> 00:27:39,180
We have to set a direction to one if we want it as input.

359
00:27:39,210 --> 00:27:41,680
We have to keep its direction to zero.

360
00:27:41,820 --> 00:27:51,990
So P F one over here I can pass 2 x 2 0 x 02 here and this essentially means it's number one.

361
00:27:51,990 --> 00:28:01,140
I would explain this for you this is 1 2 3 4 0 and this is 0 x this is 0 0 1 0 here like this or bit

362
00:28:01,140 --> 00:28:05,540
0 bit 1 and bit 1 is for P F 1 right.

363
00:28:05,550 --> 00:28:10,020
Red LCD put a comment here

364
00:28:19,060 --> 00:28:23,180
and this one here I'll put a comment here as well for your revision

365
00:28:36,620 --> 00:28:43,800
so once we've set a direction register we have to enable it by accessing the digital enabled register.

366
00:28:43,800 --> 00:28:50,510
So I'm gonna come over here and see GPL a DC and is that digital enable register and because I want

367
00:28:50,510 --> 00:28:56,090
to enable P F one I'm going to pass your x 0 2 Yeah as well.

368
00:28:56,510 --> 00:29:06,040
So come over here use the sign equals zero x it's here to like this so once this is done we are fine

369
00:29:06,070 --> 00:29:10,020
we can write to the data register in order to turn on the LCD.

370
00:29:10,540 --> 00:29:13,750
So I'll simply come over here hand to keep the are you a.

371
00:29:14,260 --> 00:29:21,510
And then I'll access the data register by saying data and then I'll write 0 x or y here.

372
00:29:22,540 --> 00:29:25,310
It's sure to like this right.

373
00:29:25,390 --> 00:29:28,630
So now we're ready.

374
00:29:28,630 --> 00:29:31,280
We've written this.

375
00:29:31,630 --> 00:29:36,510
Basically what we've done is we've said set.

376
00:29:36,550 --> 00:29:43,150
So that's been one high because if X expand this is what you get.

377
00:29:43,150 --> 00:29:43,960
This is what you get.

378
00:29:43,990 --> 00:29:45,610
And this corresponds to being one

379
00:29:50,240 --> 00:29:51,220
that's been one

380
00:29:55,180 --> 00:29:58,160
that's been one digital like this.

381
00:29:58,480 --> 00:29:59,050
OK.

382
00:29:59,100 --> 00:30:01,170
So let's build and see how this works.

383
00:30:02,250 --> 00:30:06,780
I'll click over here to build and it's finished building successfully.

384
00:30:06,810 --> 00:30:11,750
Now we have to download onto a board that's two days see how it works.

385
00:30:12,060 --> 00:30:13,050
Oh sorry about that.

386
00:30:13,050 --> 00:30:16,220
We're working with GPO port f not port a.

387
00:30:16,230 --> 00:30:21,810
So everything here should be changed to f our LTE is connected to port F

388
00:30:25,200 --> 00:30:25,890
right.

389
00:30:25,890 --> 00:30:27,140
This is the red OLED.

390
00:30:27,180 --> 00:30:29,040
It's connected to p F1.

391
00:30:29,190 --> 00:30:32,070
So everything here should be about Port f.

392
00:30:32,370 --> 00:30:36,280
Let's build again a click over here to build show.

393
00:30:36,320 --> 00:30:42,640
I'm going to click here to download onto my board and I can see the red LDS on.

394
00:30:42,810 --> 00:30:43,380
Right.

395
00:30:43,380 --> 00:30:49,500
So let's create a pseudo delay here to help explain the LCD when we get to the time a section and we're

396
00:30:49,500 --> 00:30:51,580
going to create more accurate delays.

397
00:30:51,630 --> 00:30:57,120
But over here we're going to create a very simple delay which is actually a forced DeLay.

398
00:30:58,300 --> 00:31:04,840
Our code is delayed M.S. And this is going to accept the millisecond amount as argument.

399
00:31:05,060 --> 00:31:09,200
It's a mess and I'll come over here I use a nested loop.

400
00:31:09,210 --> 00:31:15,990
Basically this this is an empirically derived value we're going to use here and this is based on the

401
00:31:16,080 --> 00:31:19,790
16 megahertz clock frequency of our system.

402
00:31:19,800 --> 00:31:26,670
So if your system is operating at a different frequency which isn't 16 megahertz this delay won't be

403
00:31:27,300 --> 00:31:27,950
accurate.

404
00:31:27,960 --> 00:31:34,670
And also this is tied to how long it takes for our call you efficient compiler to compile our stuff.

405
00:31:34,680 --> 00:31:41,450
So this also takes into account that we usually call your vision compiler here but this a pseudo delay.

406
00:31:41,520 --> 00:31:46,770
We don't care about accuracy much delay accuracy at this point when we get to the time of section we'll

407
00:31:46,770 --> 00:31:53,220
see how to create more accurate delays but this would just help us do things like blinking LCD since

408
00:31:53,220 --> 00:31:55,050
we've not studied about timers yet

409
00:32:01,940 --> 00:32:08,150
so I say for int i equal zero ice less than the parameter passed by the user a plus plus in India I'm

410
00:32:08,150 --> 00:32:20,780
going to have an inner loop I see for j equals zero G is less than J is less than three thousand one

411
00:32:20,780 --> 00:32:22,060
hundred and eighty.

412
00:32:22,100 --> 00:32:29,420
This is an empirically derived value it's derived experimentally and I said the computation is based

413
00:32:29,420 --> 00:32:33,850
on our sixteen megahertz and the compiler that we're using.

414
00:32:33,950 --> 00:32:35,710
So we just use the value as it is.

415
00:32:35,720 --> 00:32:39,070
There is no explanation behind this value really.

416
00:32:40,010 --> 00:32:45,010
So we're just open and close on empty brackets here like this.

417
00:32:45,020 --> 00:32:45,740
So this is it.

418
00:32:45,740 --> 00:32:51,650
This is going to provide millisecond delay based on the value we pass yes if we pass 10 here we're going

419
00:32:51,650 --> 00:32:53,230
to get 10 millisecond delay.

420
00:32:53,300 --> 00:32:55,760
This is not how you should be creating or delay functions.

421
00:32:55,760 --> 00:33:02,270
I repeat when we get to that part on time as we learn how to create much more precise delays and do

422
00:33:02,270 --> 00:33:05,870
things like measure event with time it's okay.

423
00:33:06,080 --> 00:33:13,250
But for now we can use this when I copy a prototype of this function and put it over here and I'm going

424
00:33:13,250 --> 00:33:16,900
to call it a delay function before I do that I'm going to cut this year.

425
00:33:16,910 --> 00:33:21,800
This one that writes to the pin I'll cut it and bring it in the main loop and then I'm going to call

426
00:33:21,840 --> 00:33:23,010
I delay M.S.

427
00:33:26,430 --> 00:33:32,160
And then I'm going to say delay hundred m s by passing one hundred here and then once that's done I'm

428
00:33:32,160 --> 00:33:44,630
going to set this low and bring this over here and then I'm going to change this to set this below.

429
00:33:44,880 --> 00:33:47,420
I'm going to use the opposite of this.

430
00:33:47,420 --> 00:33:49,680
Operator I remember this the friendly way.

431
00:33:49,680 --> 00:33:52,170
Friendly way of setting the pin high.

432
00:33:52,200 --> 00:33:58,320
This means you set only the pin you are dealing with high without affecting the other pins in the Indy

433
00:33:58,320 --> 00:34:05,040
register to do the same for setting low to set only the pin we are interested in without affecting other

434
00:34:05,040 --> 00:34:05,850
pins.

435
00:34:05,850 --> 00:34:11,430
We put no son assigned here and then a two day like this.

436
00:34:12,000 --> 00:34:12,360
Right.

437
00:34:12,360 --> 00:34:15,160
And this will set only our pin 5 pin 1.

438
00:34:15,160 --> 00:34:18,590
This was actually our pin 1 low right.

439
00:34:18,690 --> 00:34:20,090
So this was set a pin low end.

440
00:34:20,100 --> 00:34:25,770
Once we've set that I want to delay that at 100 milliseconds or pull our delay function here.

441
00:34:26,010 --> 00:34:35,050
And once that is done or click over here to compile and click over here to download onto the board I

442
00:34:35,050 --> 00:34:39,350
can see the LCD is blinking at the hundred millisecond rate.

443
00:34:39,430 --> 00:34:44,160
So this order is for this lesson if you have any questions at all regarding annual 4 we've done.

444
00:34:44,500 --> 00:34:45,370
Just send me a message.

445
00:34:45,370 --> 00:34:49,540
You're leaving the questions area and I shall see you in the next lesson.

446
00:34:49,540 --> 00:34:50,290
Have a good day.
