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
to write a very simple interface that can make our microcontroller serve us an SBA master to communicate
with an SBA slave.
So over here we're just going to show the various steps required in order to be able to do that.
So we're going to design a system basically that allows our microcontroller to send alphabet to an SBA
slave.
So in our project we have an imaginary SBA sleeve which we are going to interface with.
And after this example we're going to take a look at a much more practical example.
We're going to take a look at much more practical example and this will be right in the driver to interface
with a graphic liquid crystal display an LCD screen for plotting graphs etc. and we're going to write
the SSA driver for that after this one.
But let's take this very simple example first so that you can see how simple it looks before we start
dealing with the LCD.
Because what happens is different SBA an eye to see slaves have their own memory maps so often at times
when you are interface and to a particular SBI or a to see slave.
You spend most of your time communicating using these specific address address locations required by
that device.
And this this or these address locations differ among slave devices.
That is why in this first example we're not going to write the code for any particular slave.
We have an imaginary slave.
We are just going to demonstrate how to initialize the GPA to initialize the SSA module select the marginal
slave and send the alphabet A to Z to that slave and then we're going to take the LCD as a slave in
the next lesson.
So I've created a project here.
I'm calling this simple SSI and I'm going to come over here to target this tea and 4C.
One two three right and I'll drop down over here.
Source group I'm going to name it up
and I'm going to create a new far right click add new item to c file I call this main
and I'm going to set my debugger here.
This is the distilleries ICD.
I come to cities and then resets around over here.
Okay.
And then.
Okay.
And then I right click here and then include follow on to this file here like this.
Right.
So we start off by opening our main function into main and then open close and then open our infinite
loop while one open and close.
Right.
So we're going to write two functions for our SS I.
Or SBA module.
And we're going to write these functions down here and then we'll call them from the main function.
So before we we write the function is let's recap on the various steps we need to take in order to properly
configure the SS I or SBA module so I'll be using the name SS here because TVC often refers to the SBI
as SSI too I'll be saying SSI just keep in mind is still SBA.
So in order to use in a peripheral device as we know because of the clock gate and mechanism we've got
to enable clock access to the power for a device.
So we'd have to do that.
But apart from that we would have to set up our GPL you first and then go on to set up our SBA module.
So we need to enable the clock to GPL open using the RC GC GPA or register.
Then after that we go to the alternate function select register and set the pin as sporting a function
once that is done we go on and set the digital enable pin.
We digitally enable our SBA piece and then we go to the controller register and assign SBI as the alternate
function that we wish to use.
Once that is done then we can go on to start initialize the SBA module itself.
And with that we will start off by enabling clock access to the SS a module using the RC GC SS I register.
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
register and also we've gotta set the mode to phase that polarity and we do it as using the SS I see
our 1 C I receive a register which is the SS I control register 0.
Once that is done we're going to set a y SSI module which is all microcontroller to master and we set
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
control register 1 which is SS I see are 1.
Once this is done we can go ahead and enable the SS AI module through the SS AI control register 1 again
then we will be done with the is setup now to select our sleeve we set the slaves select signal.
So if we have multiple slaves would have to select them by sort of set and the slave select right.
So this just a brief overview I don't expect you to remember since we're going to write a code here
which come down here start a function I call this SSA in it.
I
know it this is a void function open close like a nation.
We start off by allowing clock access to the SSI module and the GPL.
You report that our SSI will be connected to.
So I'm gonna come over here and say RC GC system control is in the system control system control RC
GC SS AI and then we're going to use SSA 1.
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
to SSA 1
so this will enable clock access to SS I want once that is done we come over here
actually to reduce the typing noise I'm just gonna bring this here.
Come over here and then we're neighbor clock access to keep your port D for the SSA.
Once that is done we're going to enable clock access.
Let's say our slaves select being is going to be connected to GPL you port F so we're going to enable
clock access to GPL you f as well
once that's done we're going to configure port deep in three and one for the SS I clock and SS I transfer
lines respectively so we start off by doing it at proper we would disable the analog mode by accessing
the M select for these pins and then we're going to digitally enable these same parents once that is
done we're going to enable the alternate function
and once that is done we're going to assign the alternate function to be SS i1
and we'll do it by clearing it first.
So we first color and then we set in the PTL register.
Then we set like this.
OK so once this is done we've got to configure P F to us.
This leaves select a pin.
And this is basically set in the pin as an hour to put the pin so you can post the video and try to
do that yourself since you should be familiar with that.
And like I said or if I've not said it you know how to look locate registers from the data sheet.
So if there is a particular register or a particular assignment that you do not understand you can always
go to the data sheet.
For instance let's say let's say one week later you sort of open this example and you see this line
here and you want to know why this line.
Why do we pass to here.
Or you have to do is expand this to here this hexadecimal to I should put it like this so they you know
it's hexadecimal too.
So expand this into binary form and then you would see the bit that is enabled if you find a bit of
data and there would you simply need to go to the data sheet locate this register and read the meaning
of that bit.
And in this case you realize that by setting bits one in the RCC SS a 1 register we enable SS I module
1 right.
And you can do it for all of the other registers.
OK.
So we did tally enable our sleep select pin and I'm going to set it as outputs by access in the direction
register and I'm going to initialize it by keeping it high over here like this.
Once that is done we can go and do the the SBI parameters configuration such as set in it to either
slave or master sets in the out the pole the polarity to phase
and other things.
So we start we start off by disabling the SBA module
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.
And once that is done we're going to add a pre-schooler off to.
So we access the pre-schooler register to do this
and once this is done we're going to set the clock to eight mega herds SBA mode and 8 bits of data.
And we do this by access and the
control register 0 and that's what we have.
And once we've done this we can enable the SSI module
right.
So this over here initialize is the SSI.
This the initialization sequence for the SSA.
So.
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
write to the SSA module.
So it's also going to be a void going to save for it.
This would be SS I
right.
And it's going to take us argument.
What we want to write
open close so too right.
We need to set the slave assets law first and then we wait until the fight for it's not empty and then
we transmit the debate.
OK so first and slave I said is GPL you f and then we said data register would disable our slave I said
to be we disable our slaves elect been by passing through X it's your fault over here.
Once they done we'll wait until the fight for is not full and we do this by accessing the SSI status
register.
I'm just going to say while
SSI 1 status register and 2 while this is equal to zero
we just wait here.
And once we've made sure the FIFO is not food we can transfer our data into the SSI data register.
So say SS I won the R because the argument passed to the function which is data and once that is done
we can keep the slaves select line.
Hi
but before we do that we've got to wait for the transmit to be complete.
We have to make sure that transmission is completed so we can use another while loop here.
So I'll say a while
SS i1 studies register and this time zero x once you so you can go to the data datasheet and see what
this means by checking the SS.
I stayed to register and expand in this to it to its binary form.
If you do that you would see which bit it corresponds to.
Okay so once this is done we simply say
keep the F
data register pass 0 x 0 4 over here and stay here.
Right.
So this is how simple it is to write to the SSA module.
But the problem is when we start interfacing with other slaves.
The slaves would have various requirement.
You would have to send a number of commands you have to be able to differentiate between right in data
to the slave versus right in command configuration command to the slave.
Something like something like an accelerometer or a gyroscope.
You may need to configure its first.
Maybe you have to configure it to read that data in 8 bits 12 bits or 16 bits and in order to do this
you've got to write commands to the gyroscope so right in the command would have to go through a different
sequence which will be different from reading actual data and perhaps the gyroscope is not actually
a good example because here you're right in command and ingredient data.
Let's say the LCD which we shall see we would have to write command to the LCD screen as well as write
data to it.
So we would have to write command such as we would have to write a command to clear the screen write
a command to configure the LCD such as say the LCD configuration we've got to write the LCD physical
parameters as a command to the LCD for the initialization sequence and the where we have to do this
will be somewhat different from right in raw data.
For instance there is something known as the IRS and the US line we've got to set the R S line low.
We're right in command instead of C S lay high but this is just a simple example with regards to LCD
or graphic LCD especially the one we're going to deal with with other sleeves.
It's a bit more nuanced.
They've got a particular sequence for sort of interacting with them but this very clean example shows
how to initialize the SSA module and how to write to it right.
So I'm going to bring the prototype here
so when we are ready to test this file we have to do is initialize
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
say on sine character
all right over here and in here I'm going to use
going to have a loop here c for
i a coarse character a and I is less than character C less than or equal to should we include see to
it.
Plus plus
C as I can call SSI right.
All right
right.
So this is all that will be required if we have an SS a device or S.P. I slaved device that receives
that we've connected to our board accordingly.
This is what will be written and if the slave defied device can easily decode the data it would just
receive ABC and display it but like I said we're not going to try that because we don't have I don't
have that slave device.
This is just to show you the initialization in the right sequence.
So that's all there is to it.
For this lesson we can make sure there are no errors at least by compiling it.
OK.
There are no errors so that's all there is for this lesson.
And I'll see you in the next lesson as we write that drive for the liquid crystal display.
I'll see you later.