Hello.
Welcome back.
In this lesson we agreed to see how to develop the new arts driver for awhile.
Tim 4C One two three microcontroller.
Gonna create a new project by coming over here near you Vision project creates a new forward for this
this you at
then the project I'll call you out and I'm going to select my board Tim 4C 1 2 THREE 2 H 6 p.m.
okay and then the Simpsons I'm going to select the core on the device or select this startup.
Okay.
This is it.
My target is the Tim 4C 1 2 3
the group here.
I'm gonna rename it to AP.
Gonna right click a new item that S and I'll give it a name main.
So we have our main dot S4 so we going to configure the um the you peripheral on our microcontroller
and we've got a number of U S that we can use.
I think we have you to zero one two three and even four in this um experiment we're going to use you
at zero the R X line you are just two lines there is you receive and transmit our X and T X so you are
at zero I'll put a comment here
we find the RDX at P is you remember the UT is connected to a uh no more GPL U.
So in order to use the U.
We need to configure the GPL u to be s p i o special purpose input output.
And another way of saying this is we need to configure the GPL you for its own tonight function one
of its alternate function because a single GPL European could have multiple alternate functions.
You can have one pin that you can configure to serve as a you to been an ABC pin or even a pin.
Right.
So we're going to use you at zero which is connected to p a zero and P A one hour X and T X respectively
okay.
So we would need to configure P is European one for alternate function.
Right.
So um let's go to the data sheets and um and find the the addresses of the relevant registers that we
need when I open my data sheets.
I've got it over here.
We started with GPL u a um
less control F for GPL.
You see we have GPL u here.
I'm gonna go to um register descriptions and um I'll be brought here.
So I'm going to get the GPL you a bass address.
This is a closed is a Yeah.
This is it copy it.
And then
when I come over here and then I'll say GPL you a on this code base.
Q You this is the base address I just delete this from here and then what we also need is the um the
system control base and then the system control offset.
We already sorted that out in the previous the previous lessons so I'm just gonna bring that piece of
code that we already wrote the assignment we did for that.
So this is a system control base address because we need to enable clock access to GPL 8 and we would
have to go through a system control to do the right.
So we've got GPL you APIs.
Now we can get our various registers we would need to configure the um we need to configure the digital
we enable and then we may have to not May.
We definitely have to access the alternate function register to select the alternate function.
We also have to deal with things like disabling analogue functionality and perhaps you know yeah we
we need not touch the content the direction register here.
So we can leave that out.
So I'm gonna get the.
Or just create symbolic names for the registers that we are going to be touching.
We're going to be accessing GPL u a GPA a
GPA a TV end which is the D to enable register
D and underscore our
no offset first.
Q You don't have that yet so we leave it and they won't do GPL u a d n the register e course Baz
plus the offset like this.
Okay the next one is gonna be.
Q Are you a
alternate function select offset
we do not have it so I'll just leave it blank then GPL you a net function select register this equals
the base
plus it's offset
Um yeah I think these are the two registers we um we need you I'm trying to have a minimalist code over
here.
Um okay we'll need a P C T L registered to think we need that s I don't want us to sometimes some register
the um some of the registers have got different values the way we want them so often the best practices
is even if they register its default value is your issue and you want that bit to be 0 you should actively
set it to 0 but you know that to minimize the code I sometimes avoid that we need a P T O register uh
um Oh c GPL you a
P C
offset first a Q you then you Yeah a peace treaty L to register
es equals the base plus the offset
plus the offset this one here
right.
We have to teach to enable you only have this.
Okay so um a symbolic name for enabling GPL u e to enable GPL U A we need to go to the system control
register and then we need to we need to set bits number 0 to 1 we need to go to the system control RC
GC GPL you register this one here sets bits number 0 to 1 and we shall find in the data sheet so I'm
gonna create a symbolic name for that I'm simply going to say GPL u a QPR U E E N E course
shift 1 2 bits number 0 and then over here we need to enable clock access for the M for the U ut as
well and to enable clock access for the U ut we would need to access the our C GC you ought to register
we have the RC GC GPL you register to enable clock access for our various GPL your ports and because
we have multiple U S we need to go to the RC GC you are registered to enable clock access for the U
S that we want to use so I'll see you at 0
e end and this is also passing one or two bits number zero so we need the we need the RC GC you UT register
we need to create a symbolic name for the we need to get the address and give it a symbolic name because
we have just RC GC RC GC GPL you here we need you UT
so um the RCC you ought to register is simply going to be an office on offset from the system control
base.
So I'm gonna say the same way we have GPL here.
I'm going to have our GC you out here so see RC GC You got offset.
We do not have that so I'm going to leave it and then I'm going to see
this control you know system control is often written with a T but because we are given our own names
we can write it how we want it but we can fix this and make it look good.
Just change the R to t here okay.
System control so the registry court system control RC GC you art school are and this is going to be
the system control base
plus the offset.
RC You see you are offset like this.
Okay so we would have to fetch this from the data sheet as well.
Um and then we've got the um we've got a bit shift to enable our to enable or you what.
Right.
You want an GPL you A.
So now we can go to the data sheet and fetch what we want.
All right.
Now let's go to the data sheet and get the um the offset of the various registers.
Let's start with the RC GC.
I'm gonna go to my data sheet here.
Control f 2 search and then you can simply type our CTC you out and then I'll hit enter and then it
brings me here.
Register sixty three RC GC you to click over here and the offset is 0 x 6 1 8 0.
Copy this and bring it over here
and we can read a bit about it.
Like I said this register is used for enabling the clock access for a while various blue dots.
Let's see what bits number 0 does etc. Over here.
You are two more to zero run mode.
Clock gate in control.
If we pass 0 2 pitch 0.
If we set the bit 0 2 0 you are two modules you is disabled.
If we set it to 1 we enable and provide a clock to you at module 0 in run mode.
So that is why we have this symbolic name shift 1 2 bits number 0 for you to enable.
Okay so the next register is the GPL.
You're a digital enable register to end.
So I'm gonna go to GPL you gonna come up here and search GPL you and
we just go to click click register descriptions here.
Then as you bring us to the registers and what we need is the date the deep end to teach to enable a
register so we can keep scrolling till we find it
should be down here somewhere.
Okay.
We would need.
We need the alternate function selector register as well.
So how about we just copy it.
Although we are looking for the key.
So copying the offset of the alternate function select and put it over here.
Right.
Let's go back
and where is the DC n
k.
See goodness.
Okay here we go.
GPL duty and Okay copy this.
D n no.
We're looking for the P.C. TTL.
Or it.
Let's go scroll down.
This is the port control register.
Copy this
you can read.
You can read it all these registers if you want to learn more about them.
And if you want to read more about the U S You can read more about the US from the data sheet just like
we saw how the the data sheet provided step by step instruction for initializing the GPL you know what
pay a section does the same step by step instructions for you at and in fact for any peripheral that
the m the microcontroller provides I'm scrolling up to the bits that talks about initialization so just
bear with me so it should be under you.
There is always a section under initialization that talks Okay so it talks about the initialization
procedure here.
So if you want to read more about it you can do that or not.
This is GPL.
But if you go to the U UD section there is if you go to the section under you UT there is a subsection
called initialization and the configuration and it gives the steps for initialize.
OK.
So now we've got our we've got our GPL you registers with regards that are you at.
And now let's take a look at the other registers.
We would need to enable to you but we would need to sort of configure certain you registers.
We would need to configure that you at in transmit mode or receive mode or both.
We would need to decide d the data length we need to decide whether we are using FIFO or not we'd need
to decide whether we use an interrupt or not.
And we need to enable the EU at all the stuff we do them using the other registers so I'm going to come
up here and search you are to gain control if you add and brings us here and then I'm gonna go to register
descriptions.
So this is the you at the register.
Do you at data register would need it.
So what I'm gonna do is I'm going to create a symbolic name for that.
I'm gonna come over here you at zero pace you need to grab you at zero base OK.
Once we've cropped that you to zero
once we've grabbed that we um we say you at zero.
Um.
These are just the name of the register.
These are offset
to you.
And then they released the register itself you add zero.
These are the score Ah.
And this is simply the base plus the offset.
You got zero base over here.
Plus the TR offset.
Okay so the scrubbed the um the offset is your X years you mean it is the same as the base address.
No problem.
But we have to find the base address the base address should be here.
So over here get over here gives us the base address of our various You are modules.
Look at that we've got seven different you are two modules.
So I'm going to copy the base address from here.
Highlight this control C to copy and paste it over here control feature paste.
I'll clean this right.
So we've got our you at data register.
Um let's go and you can read more about this if you want.
Um let's go see if we have that important registers.
Of course we need more registers.
We need to deal with at least eight registers.
This is the you at Flag register.
So this we would need to check whether the transmit flag said they receive flag sets et cetera.
So this is unimportant.
Register.
I'm going to copy this symbolic name and then I'm going to copy the offset sorry and then I'm going
to create a symbolic name for the register.
So I'm gonna see you at zero f r register f r offset as you say offset can you already copy this
or simply paste this over here and then you add zero far the register queue you as the um the base your
zero base plus the offset like this.
Okay.
Let's move on.
Okay.
So we will be taking a look at the T X R X flags bits number form bits number five.
We would monitor these flags to see whether there is receive or transmit to flag.
They did receive or transmit flags asset or whether you are too busy.
So when we start creating symbolic names for these t x f f and our x f f or f e then should know we
are talking about this but we'll talk about that later.
So we would use t x f e to check if you transmit FIFO is empty t x f f t check if the U receive FIFO
is full right.
And then there is the receive FIFO and then there is the trust me FIFO fool.
And then there is receive FIFO empty.
Like I said I'll show you.
Right.
I spoke about the um the section on initialization on the configuration.
Okay so over here if you want to read more about a US or if I'm saying something and you don't quite
grasp it they provide initialization and configuration steps here step by step for doing what we are
we are gonna do so you can spend some time reading this if it's not so clear.
And of course you can send me your questions if you have any questions you can send me a message or
leave in the queue and a section but all of this is written here.
I know this because I've read this stuff before.
Yeah goodness.
Let's go back to the top and look at you at Control F and we need to go to register descriptions Okay
so we had just created a symbolic name for our flag register see other relevant threads.
This will require
this that you at low power register.
Well we're not dealing with low power.
No we get this on the day importance register this to you at integer baud rate device.
So we would have to set the board rate of where you are to communication where we want the standard
nine thousand six hundred or the other popular one of which is one hundred and fifteen thousand two
hundred would have to said that and to set a broad rate to the two registers.
There is the integer register and the fraction register so we need to get this register.
I'm gonna copy this and I'll show you how to calculate the portrait rate when we start calculating it.
So I'll see you at 0.
The name of the register is integer portrait IPD a P R.
And then the offset for it copied it so simply pasted over here and we say you are 0 and I P R D the
register.
This is E Q You and it's simply the base address of you at 0.
Sorry but the plus the offsets over here.
Okay.
Right.
Let's go to the next one the next one should be the fraction 1 so we would have to.
Okay we just explained this while we are here would have to write to the board rate integer part here
the first sixteen bits of this that two bits register is the part where we started the the board rate
the board rate is going to be it is going to have a hole number in a fraction we take the whole number
and we put it here in the first sixteen bit of this register the fraction bit is going to be stored
in d You are the fractional board reach device.
And this the um this the offsets for that register so I'm going to copy this and create a symbolic name
for it
you 0
F P R D offset it Q you this is it and then the name of the registers you at zero P R D on a score r
and you know this by now simply base address
plus the offset
K control C control V right.
Okay let's see.
Okay.
Our next register is the line control register and this is the register that we shall use to sort of
configure the day length whether we want 8 bit wet lint or 7 bits would need this register to figure
out the data length psychopathy the offset and come in created
you at zero line control register it's often written us LC Ah h right let's see yeah it's written us
DLC Ah h okay
offset
a you this the offset and we can create the register you are 0 LC RH R for the register P Q You we grew
up the base address and pasted over here we are to the offset as well.
Copy paste it over here okay see you on next register is that you control register and we shall use
this to enable and disable what are you not going to copy the offset from here
you at zero control register CTO we call this this is the offset queue you
CTO to register itself.
Q You
this is base pays
plus offset.
Right.
Okay so we'll need at a register since we'll be talking about interrupts.
How about we just add the registers that would help us with enabling you to interrupt in other things.
So just go ahead and art or relevance register so that the next time we talk about you but we wouldn't
need to add any you know any new registers who we wouldn't need to create symbolic names for registers.
So yeah with this we would we would just need to check our sort of status register.
We just need to add other registers to check the status whether you know it should be called a status
register.
Anyway.
Let's just add all registers that we need for you at our X T X and interrupt.
So that when we're dealing with other topics when you we wouldn't need to add in a Fed registers.
Okay so I'm going to go ahead and look for more registers that I think will be relevant to us
okay.
Register 4 5 4 level select.
We wouldn't need this.
Okay.
Interrupt mask this unimportant to reduce that for interrupts.
I'm gonna copy this creates a symbolic name for it.
You had zero
I m offset Q you
you are at zero.
I m r a Q You assume zero days plus I am offset.
Right.
Moving on
let's see we saw one which we got to fight for we may need to experiment with this.
Um I'm gonna create a symbolic name for the interrupt FIFO level select as well.
Copy this.
You got zero.
I f and this offset a Q you.
This is it.
And then you add zero I f Ellis and the score R E Q You is the base you add zero base plus the offset
this one over here like this.
Okay moving on the C the C
Okay.
So this the U S ALL RIGHT AS row interrupts that is registered.
Definitely useful.
I'm gonna copy the offset.
Come over here.
You had zero arrays offset it.
Q You pasted that here.
You had zero arise are you.
Q You as the base you had zero base
plus the offset this one over here.
Patient over here.
Right.
Moving on
screwed down.
This is most.
Interrupt studies we um we sorted this register out did we not.
0 x 4 0 okay.
Okay we can leave that one out.
Um let's see.
Okay here we go.
Okay.
This unimportant want the register.
I see our register as the interrupt.
Claire register.
Okay this is going to be useful Claire and interrupt.
So come over here.
You at 0 ICR offset
you Q you then you at 0 ICR Are you Q You the base
plus the offset ICR offsets here like this
right.
So I think we have enough registers.
Okay let's hope we've not missed an important register.
Right.
So now we are going to create symbolic names for the various constants that we shall be right into the
various registers.
So for instance to enable the um the U to module we may need to set bits number maybe bits number 1
to 1 we may need to set the PIN number 2 to 1 or something.
We are going to create a constant 2 Hope is such that we just write it constants to make liquid more
readable.
And you know what I'm talking about because we did it for the other lessons.
So let's do that now.
Okay so let's start which creates a constant for check in if the receive FIFO is empty.
I'm going to call this you at
you out and we're going to be applying this to the um the flag register.
So we'll say f our and then our rigs will receive and then f for FIFO and E for empty.
And this basically will be to perform an end operation with um pit number five set to um 2 1.
And this is what it looks like in hexadecimal form right.
If you explained this this hexadecimal number you see that bits number five is what is set to 1 in the
entire 32 bit
receive FIFO empty
okay.
The next one is going to be a constant to set our data lines to 2 8 bit.
So I'm gonna see you at
and that the register will apply this to use the line control register.
LCR H.
And we're going to say the word lent w lend to 8.
Q You and the constant is this
this means
each bit word length right the next one will be to enable the EU to vie for to anybody you are to fight
for.
We would need to access the um the line control register so I'm gonna stop you out of line control register
again and five enable.
It's gonna be equal you know.
Um the hexadecimal is basically set in between number five and the 32 bit to register certain bits.
Number four sorry.
This is bits number four.
If you explain this this is this one hexadecimal digits would give us four binary digits.
And this one here is it's 1 0 0 0 right.
But because we count from zero this one would end up corresponding to bits number 4 or bits number five
is the fifth bit but because we come from zero it's bit number four.
And so this is for
enable 5 4.
Okay the next one will be to um to enable the U.
And this one we going to access to you utter control register.
So see you UT CTO you're right.
E N E Q You and this is basically set in bits number 0 2 1
enable you to write the next one here is to check if they receive five full time all total kid and I'm
simply going to do you what I m because we're gonna apply that to the I am register interrupt mosque
and then I'm gonna see our t i m e q u
right.
Okay so now we have done a into symbolic names and we shall stop developing a try find a next lesson.
So I'll see you in the.