1
00:00:00,940 --> 00:00:09,130
So in this lesson we're going to write our first S.P. or SS I driver and in this lesson we're just going

2
00:00:09,130 --> 00:00:17,500
to write a very simple interface that can make our microcontroller serve us an SBA master to communicate

3
00:00:17,560 --> 00:00:19,810
with an SBA slave.

4
00:00:19,810 --> 00:00:25,330
So over here we're just going to show the various steps required in order to be able to do that.

5
00:00:25,540 --> 00:00:33,820
So we're going to design a system basically that allows our microcontroller to send alphabet to an SBA

6
00:00:33,820 --> 00:00:34,540
slave.

7
00:00:34,600 --> 00:00:42,770
So in our project we have an imaginary SBA sleeve which we are going to interface with.

8
00:00:42,970 --> 00:00:49,150
And after this example we're going to take a look at a much more practical example.

9
00:00:49,300 --> 00:00:54,700
We're going to take a look at much more practical example and this will be right in the driver to interface

10
00:00:54,700 --> 00:01:03,160
with a graphic liquid crystal display an LCD screen for plotting graphs etc. and we're going to write

11
00:01:03,190 --> 00:01:05,660
the SSA driver for that after this one.

12
00:01:05,710 --> 00:01:11,890
But let's take this very simple example first so that you can see how simple it looks before we start

13
00:01:11,890 --> 00:01:14,030
dealing with the LCD.

14
00:01:14,170 --> 00:01:26,410
Because what happens is different SBA an eye to see slaves have their own memory maps so often at times

15
00:01:26,470 --> 00:01:32,700
when you are interface and to a particular SBI or a to see slave.

16
00:01:32,710 --> 00:01:40,960
You spend most of your time communicating using these specific address address locations required by

17
00:01:40,960 --> 00:01:42,170
that device.

18
00:01:42,190 --> 00:01:49,570
And this this or these address locations differ among slave devices.

19
00:01:49,570 --> 00:01:55,350
That is why in this first example we're not going to write the code for any particular slave.

20
00:01:55,360 --> 00:01:57,180
We have an imaginary slave.

21
00:01:57,290 --> 00:02:05,370
We are just going to demonstrate how to initialize the GPA to initialize the SSA module select the marginal

22
00:02:05,450 --> 00:02:14,140
slave and send the alphabet A to Z to that slave and then we're going to take the LCD as a slave in

23
00:02:14,140 --> 00:02:15,440
the next lesson.

24
00:02:15,460 --> 00:02:17,800
So I've created a project here.

25
00:02:17,830 --> 00:02:25,710
I'm calling this simple SSI and I'm going to come over here to target this tea and 4C.

26
00:02:25,760 --> 00:02:29,260
One two three right and I'll drop down over here.

27
00:02:29,260 --> 00:02:31,300
Source group I'm going to name it up

28
00:02:42,930 --> 00:02:48,580
and I'm going to create a new far right click add new item to c file I call this main

29
00:02:52,820 --> 00:02:58,400
and I'm going to set my debugger here.

30
00:02:58,620 --> 00:03:02,510
This is the distilleries ICD.

31
00:03:02,550 --> 00:03:06,900
I come to cities and then resets around over here.

32
00:03:06,990 --> 00:03:07,400
Okay.

33
00:03:07,410 --> 00:03:07,690
And then.

34
00:03:07,730 --> 00:03:08,510
Okay.

35
00:03:08,590 --> 00:03:14,380
And then I right click here and then include follow on to this file here like this.

36
00:03:14,610 --> 00:03:15,390
Right.

37
00:03:15,420 --> 00:03:25,420
So we start off by opening our main function into main and then open close and then open our infinite

38
00:03:25,420 --> 00:03:30,880
loop while one open and close.

39
00:03:30,880 --> 00:03:31,320
Right.

40
00:03:31,720 --> 00:03:35,220
So we're going to write two functions for our SS I.

41
00:03:35,230 --> 00:03:37,060
Or SBA module.

42
00:03:37,060 --> 00:03:42,170
And we're going to write these functions down here and then we'll call them from the main function.

43
00:03:42,190 --> 00:03:49,870
So before we we write the function is let's recap on the various steps we need to take in order to properly

44
00:03:49,870 --> 00:04:00,100
configure the SS I or SBA module so I'll be using the name SS here because TVC often refers to the SBI

45
00:04:00,520 --> 00:04:07,260
as SSI too I'll be saying SSI just keep in mind is still SBA.

46
00:04:07,360 --> 00:04:14,410
So in order to use in a peripheral device as we know because of the clock gate and mechanism we've got

47
00:04:14,410 --> 00:04:18,440
to enable clock access to the power for a device.

48
00:04:18,450 --> 00:04:19,840
So we'd have to do that.

49
00:04:19,930 --> 00:04:27,310
But apart from that we would have to set up our GPL you first and then go on to set up our SBA module.

50
00:04:27,310 --> 00:04:34,090
So we need to enable the clock to GPL open using the RC GC GPA or register.

51
00:04:34,090 --> 00:04:41,380
Then after that we go to the alternate function select register and set the pin as sporting a function

52
00:04:41,620 --> 00:04:47,790
once that is done we go on and set the digital enable pin.

53
00:04:48,070 --> 00:04:58,240
We digitally enable our SBA piece and then we go to the controller register and assign SBI as the alternate

54
00:04:58,240 --> 00:05:00,340
function that we wish to use.

55
00:05:00,700 --> 00:05:05,950
Once that is done then we can go on to start initialize the SBA module itself.

56
00:05:05,950 --> 00:05:17,580
And with that we will start off by enabling clock access to the SS a module using the RC GC SS I register.

57
00:05:17,580 --> 00:05:25,860
And once that is done we've got to set the bits rate using the SSA C P S R which is that pre-schooler

58
00:05:25,870 --> 00:05:33,910
register and also we've gotta set the mode to phase that polarity and we do it as using the SS I see

59
00:05:34,000 --> 00:05:40,240
our 1 C I receive a register which is the SS I control register 0.

60
00:05:40,240 --> 00:05:47,770
Once that is done we're going to set a y SSI module which is all microcontroller to master and we set

61
00:05:47,770 --> 00:05:53,770
it to a master or slave but in this case we want to set it to a master and we do this using the SS AI

62
00:05:53,800 --> 00:05:57,970
control register 1 which is SS I see are 1.

63
00:05:58,360 --> 00:06:06,700
Once this is done we can go ahead and enable the SS AI module through the SS AI control register 1 again

64
00:06:07,140 --> 00:06:16,570
then we will be done with the is setup now to select our sleeve we set the slaves select signal.

65
00:06:16,570 --> 00:06:23,410
So if we have multiple slaves would have to select them by sort of set and the slave select right.

66
00:06:23,500 --> 00:06:28,210
So this just a brief overview I don't expect you to remember since we're going to write a code here

67
00:06:28,710 --> 00:06:38,420
which come down here start a function I call this SSA in it.

68
00:06:38,680 --> 00:06:39,190
I

69
00:06:42,130 --> 00:06:49,330
know it this is a void function open close like a nation.

70
00:06:49,320 --> 00:06:55,460
We start off by allowing clock access to the SSI module and the GPL.

71
00:06:55,460 --> 00:06:59,260
You report that our SSI will be connected to.

72
00:06:59,500 --> 00:07:09,460
So I'm gonna come over here and say RC GC system control is in the system control system control RC

73
00:07:09,490 --> 00:07:14,830
GC SS AI and then we're going to use SSA 1.

74
00:07:14,920 --> 00:07:27,700
So I'm going to pass to over here and 2 is 0 x 2 and in binary you know is 0 1 and this corresponds

75
00:07:27,700 --> 00:07:28,690
to SSA 1

76
00:07:32,210 --> 00:07:37,310
so this will enable clock access to SS I want once that is done we come over here

77
00:07:44,920 --> 00:07:48,640
actually to reduce the typing noise I'm just gonna bring this here.

78
00:07:48,910 --> 00:07:56,570
Come over here and then we're neighbor clock access to keep your port D for the SSA.

79
00:07:56,810 --> 00:08:01,540
Once that is done we're going to enable clock access.

80
00:08:01,540 --> 00:08:07,750
Let's say our slaves select being is going to be connected to GPL you port F so we're going to enable

81
00:08:07,750 --> 00:08:10,810
clock access to GPL you f as well

82
00:08:18,910 --> 00:08:29,310
once that's done we're going to configure port deep in three and one for the SS I clock and SS I transfer

83
00:08:29,310 --> 00:08:40,430
lines respectively so we start off by doing it at proper we would disable the analog mode by accessing

84
00:08:40,440 --> 00:08:50,710
the M select for these pins and then we're going to digitally enable these same parents once that is

85
00:08:50,720 --> 00:08:54,350
done we're going to enable the alternate function

86
00:08:58,160 --> 00:09:03,700
and once that is done we're going to assign the alternate function to be SS i1

87
00:09:06,480 --> 00:09:09,490
and we'll do it by clearing it first.

88
00:09:09,570 --> 00:09:17,020
So we first color and then we set in the PTL register.

89
00:09:17,310 --> 00:09:18,930
Then we set like this.

90
00:09:20,610 --> 00:09:25,700
OK so once this is done we've got to configure P F to us.

91
00:09:25,700 --> 00:09:27,390
This leaves select a pin.

92
00:09:27,400 --> 00:09:32,880
And this is basically set in the pin as an hour to put the pin so you can post the video and try to

93
00:09:32,880 --> 00:09:37,530
do that yourself since you should be familiar with that.

94
00:09:37,650 --> 00:09:44,310
And like I said or if I've not said it you know how to look locate registers from the data sheet.

95
00:09:44,370 --> 00:09:51,630
So if there is a particular register or a particular assignment that you do not understand you can always

96
00:09:51,630 --> 00:09:53,040
go to the data sheet.

97
00:09:53,100 --> 00:10:00,960
For instance let's say let's say one week later you sort of open this example and you see this line

98
00:10:00,960 --> 00:10:05,130
here and you want to know why this line.

99
00:10:05,130 --> 00:10:07,590
Why do we pass to here.

100
00:10:07,650 --> 00:10:15,660
Or you have to do is expand this to here this hexadecimal to I should put it like this so they you know

101
00:10:15,660 --> 00:10:17,510
it's hexadecimal too.

102
00:10:17,950 --> 00:10:25,260
So expand this into binary form and then you would see the bit that is enabled if you find a bit of

103
00:10:25,260 --> 00:10:31,200
data and there would you simply need to go to the data sheet locate this register and read the meaning

104
00:10:31,200 --> 00:10:31,950
of that bit.

105
00:10:32,310 --> 00:10:42,900
And in this case you realize that by setting bits one in the RCC SS a 1 register we enable SS I module

106
00:10:42,900 --> 00:10:45,150
1 right.

107
00:10:45,190 --> 00:10:50,550
And you can do it for all of the other registers.

108
00:10:53,040 --> 00:10:53,540
OK.

109
00:10:53,540 --> 00:11:02,450
So we did tally enable our sleep select pin and I'm going to set it as outputs by access in the direction

110
00:11:02,450 --> 00:11:09,710
register and I'm going to initialize it by keeping it high over here like this.

111
00:11:09,710 --> 00:11:21,220
Once that is done we can go and do the the SBI parameters configuration such as set in it to either

112
00:11:21,260 --> 00:11:27,410
slave or master sets in the out the pole the polarity to phase

113
00:11:30,040 --> 00:11:31,560
and other things.

114
00:11:31,600 --> 00:11:34,630
So we start we start off by disabling the SBA module

115
00:11:38,940 --> 00:11:47,510
and then we want to say we're using the system clock and we do this by set in passing 0 to the ICC register.

116
00:11:47,510 --> 00:11:52,100
And once that is done we're going to add a pre-schooler off to.

117
00:11:52,230 --> 00:11:54,840
So we access the pre-schooler register to do this

118
00:12:00,470 --> 00:12:09,980
and once this is done we're going to set the clock to eight mega herds SBA mode and 8 bits of data.

119
00:12:10,990 --> 00:12:12,760
And we do this by access and the

120
00:12:15,550 --> 00:12:19,900
control register 0 and that's what we have.

121
00:12:20,430 --> 00:12:24,390
And once we've done this we can enable the SSI module

122
00:12:31,320 --> 00:12:31,760
right.

123
00:12:32,390 --> 00:12:36,170
So this over here initialize is the SSI.

124
00:12:36,170 --> 00:12:40,080
This the initialization sequence for the SSA.

125
00:12:40,370 --> 00:12:41,530
So.

126
00:12:41,690 --> 00:12:47,690
So let's say we want to write to the SSI we're going to create a function here they'll show us how to

127
00:12:47,690 --> 00:12:49,490
write to the SSA module.

128
00:12:50,000 --> 00:12:53,280
So it's also going to be a void going to save for it.

129
00:12:53,420 --> 00:12:54,770
This would be SS I

130
00:12:57,700 --> 00:12:59,850
right.

131
00:13:00,280 --> 00:13:02,210
And it's going to take us argument.

132
00:13:02,230 --> 00:13:04,000
What we want to write

133
00:13:07,070 --> 00:13:10,350
open close so too right.

134
00:13:10,360 --> 00:13:19,290
We need to set the slave assets law first and then we wait until the fight for it's not empty and then

135
00:13:19,290 --> 00:13:23,110
we transmit the debate.

136
00:13:23,210 --> 00:13:32,850
OK so first and slave I said is GPL you f and then we said data register would disable our slave I said

137
00:13:32,850 --> 00:13:39,970
to be we disable our slaves elect been by passing through X it's your fault over here.

138
00:13:40,500 --> 00:13:46,590
Once they done we'll wait until the fight for is not full and we do this by accessing the SSI status

139
00:13:46,590 --> 00:13:47,700
register.

140
00:13:47,790 --> 00:13:49,140
I'm just going to say while

141
00:13:53,550 --> 00:14:02,540
SSI 1 status register and 2 while this is equal to zero

142
00:14:12,890 --> 00:14:15,470
we just wait here.

143
00:14:15,470 --> 00:14:23,850
And once we've made sure the FIFO is not food we can transfer our data into the SSI data register.

144
00:14:23,870 --> 00:14:34,330
So say SS I won the R because the argument passed to the function which is data and once that is done

145
00:14:37,110 --> 00:14:39,910
we can keep the slaves select line.

146
00:14:39,920 --> 00:14:40,200
Hi

147
00:14:43,340 --> 00:14:46,940
but before we do that we've got to wait for the transmit to be complete.

148
00:14:46,940 --> 00:14:52,490
We have to make sure that transmission is completed so we can use another while loop here.

149
00:14:52,510 --> 00:14:53,360
So I'll say a while

150
00:15:00,430 --> 00:15:13,030
SS i1 studies register and this time zero x once you so you can go to the data datasheet and see what

151
00:15:13,030 --> 00:15:15,760
this means by checking the SS.

152
00:15:15,760 --> 00:15:22,470
I stayed to register and expand in this to it to its binary form.

153
00:15:22,480 --> 00:15:26,290
If you do that you would see which bit it corresponds to.

154
00:15:26,710 --> 00:15:29,620
Okay so once this is done we simply say

155
00:15:32,270 --> 00:15:33,760
keep the F

156
00:15:36,370 --> 00:15:46,410
data register pass 0 x 0 4 over here and stay here.

157
00:15:46,480 --> 00:15:46,910
Right.

158
00:15:47,290 --> 00:15:52,860
So this is how simple it is to write to the SSA module.

159
00:15:52,930 --> 00:15:56,580
But the problem is when we start interfacing with other slaves.

160
00:15:56,620 --> 00:15:59,180
The slaves would have various requirement.

161
00:15:59,530 --> 00:16:06,010
You would have to send a number of commands you have to be able to differentiate between right in data

162
00:16:06,040 --> 00:16:11,680
to the slave versus right in command configuration command to the slave.

163
00:16:11,680 --> 00:16:16,920
Something like something like an accelerometer or a gyroscope.

164
00:16:16,960 --> 00:16:19,330
You may need to configure its first.

165
00:16:19,330 --> 00:16:25,780
Maybe you have to configure it to read that data in 8 bits 12 bits or 16 bits and in order to do this

166
00:16:26,140 --> 00:16:35,670
you've got to write commands to the gyroscope so right in the command would have to go through a different

167
00:16:35,670 --> 00:16:43,610
sequence which will be different from reading actual data and perhaps the gyroscope is not actually

168
00:16:43,610 --> 00:16:48,270
a good example because here you're right in command and ingredient data.

169
00:16:48,310 --> 00:16:56,180
Let's say the LCD which we shall see we would have to write command to the LCD screen as well as write

170
00:16:56,210 --> 00:16:57,830
data to it.

171
00:16:57,920 --> 00:17:07,620
So we would have to write command such as we would have to write a command to clear the screen write

172
00:17:07,650 --> 00:17:17,630
a command to configure the LCD such as say the LCD configuration we've got to write the LCD physical

173
00:17:17,630 --> 00:17:24,080
parameters as a command to the LCD for the initialization sequence and the where we have to do this

174
00:17:24,410 --> 00:17:27,940
will be somewhat different from right in raw data.

175
00:17:28,340 --> 00:17:34,900
For instance there is something known as the IRS and the US line we've got to set the R S line low.

176
00:17:34,940 --> 00:17:42,800
We're right in command instead of C S lay high but this is just a simple example with regards to LCD

177
00:17:43,130 --> 00:17:47,140
or graphic LCD especially the one we're going to deal with with other sleeves.

178
00:17:47,240 --> 00:17:48,840
It's a bit more nuanced.

179
00:17:48,930 --> 00:17:57,110
They've got a particular sequence for sort of interacting with them but this very clean example shows

180
00:17:57,560 --> 00:18:03,350
how to initialize the SSA module and how to write to it right.

181
00:18:03,380 --> 00:18:05,180
So I'm going to bring the prototype here

182
00:18:23,680 --> 00:18:29,140
so when we are ready to test this file we have to do is initialize

183
00:18:38,000 --> 00:18:47,570
and then let's say we said we are going to make it look like it's right in alphabet so I'm going to

184
00:18:47,570 --> 00:18:51,250
say on sine character

185
00:18:55,810 --> 00:19:01,080
all right over here and in here I'm going to use

186
00:19:04,010 --> 00:19:07,090
going to have a loop here c for

187
00:19:09,790 --> 00:19:22,020
i a coarse character a and I is less than character C less than or equal to should we include see to

188
00:19:22,020 --> 00:19:23,600
it.

189
00:19:23,760 --> 00:19:24,540
Plus plus

190
00:19:30,060 --> 00:19:37,750
C as I can call SSI right.

191
00:19:38,020 --> 00:19:38,490
All right

192
00:19:42,130 --> 00:19:42,500
right.

193
00:19:42,530 --> 00:19:51,680
So this is all that will be required if we have an SS a device or S.P. I slaved device that receives

194
00:19:53,240 --> 00:19:55,440
that we've connected to our board accordingly.

195
00:19:55,520 --> 00:20:02,840
This is what will be written and if the slave defied device can easily decode the data it would just

196
00:20:02,840 --> 00:20:09,830
receive ABC and display it but like I said we're not going to try that because we don't have I don't

197
00:20:09,830 --> 00:20:11,080
have that slave device.

198
00:20:11,090 --> 00:20:15,390
This is just to show you the initialization in the right sequence.

199
00:20:15,410 --> 00:20:16,570
So that's all there is to it.

200
00:20:16,730 --> 00:20:26,200
For this lesson we can make sure there are no errors at least by compiling it.

201
00:20:27,130 --> 00:20:27,430
OK.

202
00:20:27,430 --> 00:20:30,440
There are no errors so that's all there is for this lesson.

203
00:20:30,450 --> 00:20:36,010
And I'll see you in the next lesson as we write that drive for the liquid crystal display.

204
00:20:36,010 --> 00:20:36,720
I'll see you later.
