Hello, welcome back.
In this lesson, we going to develop a number of powerful drivers that we shall use in the rest of our
course so that we can try out much more complex systems who need these drivers when we start dealing
with interrupt with regards to our free hour, Toscano.
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
continue from the I'll copy and paste.
This project doesn't require an artist, but I'm making a copy because if I create a new project, I
need to include the path and the forward directory for the driver's licenses and the whole drivers.
But I don't want to do that.
So I make a copy of an existing project.
So I call this number 19.
And know name the project, some driver's.
Like this, and then I'll say copy.
OK, it's over here.
I'm going to click call.
May not see and I'm going to clean everything with regards to the artists, I'm going to come over here
and then.
I'm going to start from the top.
So this is the art of stuff, I'll clean this up and I'll clean the task creation as well as starting
the scheduler.
So our main function is empty.
I would delete the task functions as well or delete this.
Or delete this and delete this and actually this, you got the code we have for our you to driver.
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
for the right click or send you file over here.
I can see his horse fall and then I'll give it a name.
You ought to see.
And then finish.
OK, and then include over here, I'll create the dot h version of this dot c file I've just created
and I include for the right click Noufal I can select to follow simply C file or C file.
It's fine.
I'll see you at Dorridge and finish.
Also, we're going to include we're going to include an ATC driver, as well as extend or interrupt
to include those folks as well.
But before we created a new force, less populated the folks we currently have to, I'm going to prevent
multiple inclusion by doing if in-depth on a score you add on a school age, if not defined, then we
want to define you at that age.
Then we see and if over here, OK, so let's go to our you ought to see fault.
We're going to start off by including our that each fall so that we have access to our esteemed 32 hull
drivers.
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
you.
So this code here is how are you are in it function?
I'm going to cut it.
And then paste over here.
Contrary to paste, then I'm going to rename this, I'm going to remove the static from here and then
I'll just call this new ATX because we're going to have another version.
So I say you are in it for transmuting.
You are is a transmitter in this configuration.
OK, I'm going to go back to I may not see for.
Then.
We have our you ultraright function somewhere.
This is how you try to function.
We know this function, it is currently commented out.
We need it so cuts this.
Come to our you at that see for the hour you are at right function over here and we have to remove the
comments, select or price control, and then and then the comments are removed.
OK, once that is done, we're going to come over here.
Our future.
This one here, so we updated this function to use our you ultraright function, OK?
So I'll cut this.
And I'm going to put this over here like this.
And I'm going to delete this this the one we use in you out right function, OK, so I'm going to copy
this and put out a top here.
OK, and then this is how you are function dysfunction here called error handler doesn't exist in our
new you are to see function.
This handler is defined over here.
Actually, I'm going to delete these.
Items.
This is all me, NFL, I'm going to simplify it, our error handler, we know we're not in implementation
for error or handler.
We can leave it as it is in our mind, Ötzi, but that is not required in our UAT.
So what I'm going to do is you see this line or you are in it.
We can just initialize it without checking for errors or copy this.
And then.
I would just say, or I can leave this and see how you at.
In it, if this is not equal to OK, do nothing, just keep this condition open like this, because
we don't have our hero, everyone laugh out here and we need not bring it because we've not written
any code to handle error.
OK, so this is our you in it.
Next, we're going to configure our UAT for reception.
So this configuration, of course, uses the whole library.
We use the whole library to configure our you at four for Recept for T this one actually has the XRX,
the modest XRX.
OK, so to configure the UAT for IREX, we can just copy this function and then change mode irex to
T only or to IREX only if we are doing IREX.
OK, so this was created in Cuba Kubrick's.
OK, to make the correct version, first of all, I'm going to change the mood here from TXI Rex to
just tax only.
To make the other version, I can simply copy this.
And then there's this over here and change the mood over here, quote, I simply change it to IREX.
Such that this becomes IREX here and I'm going to delete the word imex from it, from both functions.
So we have the talks, if we want to initialize the you attach a transmitter only we use this when I
initialize it as a receiver only we use this.
OK, so once that is done, we move ahead.
To deal with the 80s, so this hour, Ewart's or you autocephaly, we have to expose our Ewart's functions
so that we can access them in our main NFR.
OK, so I'll copy this function prototype copy come to you.
Ordered each file pasted over here and then I'll do the same for the text version.
A copy of this.
And then paste this over here.
OK, so now I can come to I may not see fall and say include you, Outteridge, I say include you at
what age?
And one last thing we forgot to declare our you are Tando typedef, so this Hando typedef we've got
to cut this and take it all.
You ordered Cifas pasted over here.
OK, right, so this is where we have.
Let's build and see what we have control as to save a click over here.
The old project.
Like this.
OK.
Of course, we have a number of errors because of want you to function is being called over here so
we can delete our Ewart's from here and then our Ewart's function.
This one here is to us, you ought to in it as well.
We we've been using all the time, but we've changed a name and we've changed its location.
So I'm going to call it a new function here.
You ought to underscore, you use that to underscore you atkeson it as buttinsky.
It looks good now.
So now let's deal with the ADC.
We're going to come over here to our source for the.
And then create a new far right click you for I call this ADC Dot, see?
Then I'll come over here to include fuda Greta Neuffer.
You selected a file here so that it would type, if not defined, defined for us automatically.
So I'll give it a name, ADC.
Today.
OK, so there's the format it uses.
OK.
So we're going to write a function to enable our ADC, enable a single channel, now ADC and then another
function to reach the ADC data.
So that is what we're going to do and we're going to be using this to run some of our experiment to
understand how things work more deeply.
So inside our.
ABC, that's how far we can include our ADC is going to use bedmate or code, but we can include how
that each course, how that each has our estimate added to F4 Eckstut each.
We don't need to how far this year, but we can include it anyway.
OK, so over here, I'm taking this as an opportunity to show you how we can write to the driver without
using hard.
Of course, those of you who are familiar with my course, you know, I have numerous courses teach
and that always writing drivers from scratch.
Anyway, we're going to have this function here called ADC and it's OK.
And we're going to go to the reference manual and find out how we would be able to initialize the ADC.
So we know the ADC is a peripheral and the ADC converts analog signal to digital for us.
So we have a sensor and we have to attach it somewhere on our MCU.
And then the data that is read by the sensor is brought into the MCU.
So we have to attach it to a pin.
Because of this.
The ADC has channels, these channels are normal, GPA, your pins, but if you want to use them as
ADC pins, you've got to configure them to work as ADC pins.
OK, so in in our UMCOR tax system or in modern day microcontrollers, before we use any module, we
need to enable clock access to that module.
So what I mean by modulus in in a peripheral so the GPA is a peripheral ADC disappear for you, what
is a peripheral spy?
Just a peripheral.
Before we use any of these peripherals, we need to enable the clock access to them.
So to find the information out how the buzz of the.
Microcontroller is connected, we have to go to the datasheet document, so this document here, you
can search it on the Internet.
This is the datasheet one hundred and forty nine pages, you can simply such as the M 32 F or one one
datasheet in a way, this block diagram here in the datasheet, the document ptosis.
Oh, things are connected.
This block diagram shows the buses and as you can see, there are two types of buses.
We have the bus.
And HP stands for advanced high performance busts, and then we have the APB bus, which stands for
Advanced Peripheral Bus.
So HP, we have HP, one HP to HP, one APB to what I mean by APB is this bus over here.
Right.
So we have to know which of the buses is connected to the patrol we are interested in.
We are interested in you as well because we said our ATC has channels and these channels I just G.P.A.
where we connect our senses.
So in this example, we're going to use a one.
So we're going to use you put a pin one, so because of that, we would need to enable clock access
to your ports.
A as we can see over here, you put a has this arrow connect to it and then connect into this bus with
a name h.b one to then to enable to use GPS.
We need to enable clock access to it and to enable clock access to tell you if we need to go through
the AHP one bus.
So then what we have to do is go to the AHP one module and find a register that allows us to edit to
enable clock access to all the peripherals connected to the HP one bus.
That is what we shall do next.
Before we leave, we have to enable the ATCs well.
So let's see.
Which bus the ADC is connected to?
Where is this is the.
So this is ADC one or microcontroller has a single ADC, this is ADC one and we find an arrow touchin
ADC one and then connecting to APV two.
So meaning to enable access to ADC one, we have to go through the APB to bus.
And what that means is we have to go and find out which register in the APB to Range allows us to enable
clock access to ADC.
OK.
So to find the registers, we need a separate document known as the reference manual.
This document is called R.M. zero three eight three.
So you can simply search SDM 32 hour and.
Zero three eight three on Google and you get a reference manual for the three to for one one.
Microcontroller Ariff stands for Reference Manual.
So this has over 800 pages.
Obviously, we're not meant to read all at once.
It's for reference to the reference we are looking for as the we said, HP.
So I'm going to come over here.
I'll do control F and then type the HP one.
That is where we saw our that is where we saw our connected HP one, HP one over here.
This is it is connected.
So I'm going to switch HP one.
And over here, it brings us to a number of registers, there is h.b, one pair, four resets register.
OK, let's scroll down and see what other registers we have.
There is the H.B, one pair, four o'clock and they will register.
This sounds like what we are interested in.
So we click on this and when we come over here, it tells us.
The meaning of each bit in the register over here beats zero in this register stands for you, a enable
which one is for GPA would enable it to is for GPA.
You see a.
And what this means is we can go to zero and read what it means by scrolling down here.
We have explanation for what zero is it says Jhpiego, and.
I will put a clock enable set and cleared by software, if this is zero, then put a clock is disabled.
If this is one, then put a clock.
This enabled.
So we have two sets, but number one, we have two sets, bitz number zero to one to enable clock access
to Port A.
So that is simple.
It is located in the RCC module and the name of the register is H.B one enabled.
So we can simply do this.
We say RACC module and then h.b one enable, you see, it's a structure, we've even found it h.b one
enable register and then we say equal to we want to set bitz number zero to one so we can simply say
one because one is the same as one in binary.
Or we can see a shift, we can say shift one.
To better position zero, and this implies that this implies that.
This implies that we're going to we're going to shift one the value or the number one to position zero
of this 32 bit register.
So that is what we're doing here.
Or we can simply write one because one here is the same as one is the same as writing a decimal zero
zero zero zero zero zero one one two three four five six seven seven zeros is the same as writing this.
If we convert this hexadecimal zero zero one to binary, what we would have is zero B for binary notation
and then zero zero zero zero zero zero zero zero all the way here to one such that we would have thirty
one zeros here.
All the way to one, and this is the same as one in decimal.
OK, so we can we can write it in hexadecimal notation or we can simply write this one, or we can see
shift to one two position zero.
OK, so remember, let me arrange this for you.
I mean, if I'm doing this, I have to do it properly.
For those of you who are not aware.
For binary digits, give us one hexadecimal digit.
So that is why we have eight digits here, one, two, three, four, five, six, seven, and actually
there should be a last one.
So one, two, three, four, five, six, seven, eight.
So this zero will give us four binary zeros, the second zero for binary zeros, the third zero, and
then all four binary zeros onto the last one will give us zero zero zero one.
And this equals one.
So, in effect, I can simply just write one here, right?
This is not about ARTUS, but I cannot just drop it here without elaborating.
OK, so next, we saw this and.
We also saw that our ATC module is connected to the APB to us, we can verify that we can go back there
and confirm ATC here is connected to APB to bus.
So let's find the APB to powerful and they will register in our reference manual or come up here.
And then I'll do the same thing, control f EPB to.
And then there is APB to Perry for a neighborhood register.
I'm going to click this.
OK.
Liversidge.
APB, too.
OK, I clicked on H.B, rather.
OK, so let's scroll down and find APV.
This is AP one.
So AP to should be down here.
Let's see.
This is a screw problem.
OK, this APB, too, and when we check bits, number eight of APB to.
Therefore, enable register.
It is called ADC one end, meaning we need two sets, bitta number eight in the app to register.
To one, in order to enable the ADC so we can come over here and say RACC module.
And then we see a PB to eat and register and we want to shift one.
Two bits, number eight.
So over here, we're doing a neighbor clock for ABC, and then over here we're doing a neighbor clock
for you to be consistent.
I'm going to use this method over here, shift one to position zero.
OK, so over here we have a neighborhood clock access for our ATC module.
And then I want you to put a module.
And the reason we need your report is because you want to use P one as our ADC channel.
Next, we need to go to our Jhpiego section to find out.
OK, I have my Jhpiego.
How do I need them to work as ADC?
How do I set them up as ADC?
So I'm going to set you here in our reference manual.
And then over here we in the U.S., I'm going to go to the registers.
There should be a register set in the mood.
So there is this register called Portmore which register.
I'm going to click over here and Portmore Dredgers that tells us that.
If we want to set a particular pin to analog, OK, first of all, this Portmore Dredges, this 32 bit
register is going to start from zero and it's a 31.
In Portsmouth Register, which is known as the mortgage register or the motor or motor.
Two, it is for one person.
So you see we have more than zero here and then we have more than one would have to move the cirrhotics
bit Zurin one more than one takes between two and three more to two takes between four and five.
OK.
So Malaysia is for all passengers, more than one is for open ones, all the way to more than 15 for
all furphies.
So we are interested in pay one so there will be more than one.
So then we are dealing with between two and three of the mobile register.
So bid two and three have to be one and one before we can set up one.
As analog to setup one US analog, we have to set it two and three to one in one.
OK.
So that is what we're going to do next to one in one here.
What does that imply?
We can convert this into.
We can convert this into hexadecimal notation and we realized that we would end up with zero zero one
one zero zero one one is the same as XY.
Zero zero one one in binary issue XY.
OK.
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
remember to know what I type in the in the document is the name you were dealing with POTTY, and then
is the name of the register.
So it stands for the GPL airport.
So I simply typed you bought a and then.
Motor register like this.
And then I can simply set this by saying EXI.
And if I expand, as you see this hexadecimal number, if I expand it to binary, I'm going to.
This remember, each hexadecimal number is for binary bits.
This is the same as one one 00 and this corresponds to bits number two and bits number three.
And we know bits number two and three other bits.
We need two sets, one, one Kozmo.
That one is for P one.
It's number two and three need to be set to one one to get this analogue pin.
OK, so this means.
So it's one less analog.
Of course, you can use this method, you can use this method by shifting as well.
And also one other thing you see over here, what I'm doing is I'm simply assigning values to the register.
I'm simply assigning values to the register.
Mean in the end, the entire 32 bit register is cleaned.
And this new value that I'm assigning becomes the new value of the register.
A better way to do with this is to use the operation.
When we do this, only the bits that we want to change will change.
So in this case, only bits number eight is going to be said to one and only bits.
Number zero is going to be said to one in this register and all other bits would have the original value.
I can do the same for this.
OK, so once we've done this, the next thing we do is simply enable the ATC over here, I'm not going
to go through the ADC configuration.
That will be an entirely different lesson.
So I'll just bring the configuration code.
So we go to the ADC module.
It's quite a number of registe.
This is called control register to Squaddie Sequencer, Register three sequencer register one.
We go to control register when we set it to zero zero, its main software trigger because our ADC can
have more output, can have different triggers, we can trigger it using other sources to see the standard
trigger, which is the software itself.
Some the ADC data we just set, we just write zero to control register two and you can go to the reference
minor if interested.
You can go to the section on ADC and read about ADC one underscore.
See our two.
And then over here, conversion is going to start at Channel One, we have a single channel and then
the conversion land, we have to decide what is the conversion then.
If we had multiple channels and we wanted to sample more, we would increase the conversion rate.
But we set it to zero over here because we have just a single conversion and then we enable the ADC
by writing one to the control register to OK, if you want to learn how to write or code for all peripherals,
not just the ADC, you can take a look at my embedded systems permit or programming course.
Right, if we are to spend time going deeper into this.
This course won't end today.
OK, so next, we'll write a function to read the ADC data, so dysfunctional, right, or retender
data so it will return to you and 32 unaskable tea in the name of the function will be read analogue.
And so takes no argument like this.
And what we have to do here is first to start the ADC conversion.
We said software trigger, so we have to start the ADC conversion to do this.
OK, this one I would explain.
We're going to go to the ADC, part of the reference manual.
I'll come up here and control F and then I'll search ADC and I'll scroll down to ADC Registers.
OK, and then.
Still scrolling on a stop scrolling.
And then we're going to go to the ATCC ata, which is ADC Control Register to remember we said.
When we said control register two for software trigger.
When we write zero, it gives off to a trigger because zero basically sets the entire register.
To zero and including the bit has to decide.
Which triggered the ADC should use OK, so bits number 30 here, let's see bits, number 30, S.W. starts.
It's no 30 years code start conversion of regular channels, so we have to set bit number 30 to one
to start conversion on our ADC.
OK, and then once we started conversion, we have to wait for the conversion to be complete.
So I'm going to come over here the first and we're going to do is this one.
We're going to access the control register two and then we're going to see the operator because we want
to change only bits.
Number 30, we're going to say shift one to bits, number 30.
And David.
Start easy conversion.
Once that is done, we have to wait for conversion and when conversion is complete, we would know this
from the status register of the ADC so we can know whether the conversion was completed or not.
By checking a particular bit in the ATC status register, so let's find that so does the register.
It's called the ATC.
Underscore our ATC status register over here.
There's a bit called EEOC, meaning end of conversion bits, number one.
So it says regular channel and of conversion.
This bit is set by the hardware at the end of the conversion.
So we have to check if this bit is set and if it sets, it will let us know that all conversion has
ended its bid to number one.
So what we want to do is come over here and see one
ADC, one status register, and then we perform on an operation of this.
And the number two, the number two, because two is the same as binary notation.
Zero one like this, so this is bits number zero.
This is bit number one, this in decimal notation equals two.
So we can simply say ADC one as and number two like this and we're performing an end operation.
OK, so we say if we perform this operation and it's forced this this will indicate that our bitz number
one is not set.
If it was, then we will get stuck here.
So essentially what we are doing is waiting for conversion.
To complete and watch the conversion is complete, we would return our function is supposed to return
you into that.
To underscore t so the sense of value is going to be stored in the ADC data register.
So ADC one, D-R will just return this register and return the content essentially.
And what we are doing has returned results.
OK, so this is it, we have our ADC functions, we have it easy in it and read analog signs or so I'll
copy this and take it to our ADC to each file so that we can have access to these functions.
And I may not see.
And then I'll copy this as well.
And then pull this over here, OK?
So in the next lesson, we shall deal with our external interrupt driver, so that's all there is and
I'll see you later.
If you have any questions, leave them in the questions and this area of.