Page 2 of 2
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 12:28 pm
by jediengineer
If I need the GPIO to be input only, what is the proper way to read the data on the port? Also, the book is a little vague (for me) about setting the port direction with PDDR_x
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 12:44 pm
by seulater
To read a pin is just as simple as
If(J2[19])
{
}
IF i get time later i will help on the the other part of your question.
In the mean time take a look at the pins.cpp file this will help in the understanding of it.
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 1:21 pm
by jediengineer
Ok, I was assuming that - probably should not have asked that part - the port direction setup was a little more important. But I'll wait to hear from you. Thanks again, I appreciate it, and if you lived in my area of MA I would definitely be buying you beer and steak for the help!!
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 1:32 pm
by jediengineer
Oooohh... Something caught my eye - this makes more sense to me, and I think this was what I was imagining when I asked about setting port direction etc:
sim1.gpio.ppdsdr_b = 0x10;
sim1.gpio.pddr_b |= 0x10;
the method of address in C, versus using the uCOS - it makes so much more sense to me this way... I'm assuming I can mix C into the uCOS?
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 2:10 pm
by seulater
I am most familiar with the Nano54415, have not used the MOD54415. So bear that in mind when it comes to some code stuff possibly not being 100% accurate.
On the Manual, the fun starts on page 287 for ports.
The Port Data Direction Registers is on page 301.
I learn best with an example, so that is how i am going to do this.
On that page you will see setting a 1 for the bit makes that pin an output and a 0 an input.
Knowing this i personally then move to the pins.cpp file its quicker for me anyways.
This is located here for your board: C:\nburn\MOD5441X\system
Netburner really has done a great wealth of work for us, you just have to dig in and know where to look.
There is a great file that you should get to know. it is called sim5441x.h and located here:
C:\nburn\MOD5441X\include
In there you will see all the sructs for doing everything. In that file on line 235 you will notice all the GPIO stuff.
Knowing this when you hop over to the pins.cpp file it will make more sense.
In the pins.cpp file all the GPIO stuff starts out with sim1.gpio.xxx where the xxx is the port.
So what i do, is then see what pin i want to use. In this case it will be 19.
For this part we will set the pin high.
On line 115 of pins.cpp we see that they are setting this pin high.
this is what is there.
case 19:
sim1.gpio.ppdsdr_e = 0x08;
sim1.gpio.pddr_e |= 0x08;
So in your code you would set the pin state (Port Pin Data/Set Data Registers) on page 301 of the manual.
Note, this is for setting the pin only, making it a 0 does nothing to need to use the Port Clear Output Data Register for that.
sim1.gpio.ppdsdr_e = 0x08;
Then set the Port Data Direction Registers for an output as on page 301 on manual.
sim1.gpio.pddr_e |= 0x08;
The reason why they set the pin state first before making it an output is so there is no glitch on the pin when you make it an output. The pin state will be where you want it before it becomes an output.
Now lets make the pin low.
we now move to line 298 in the pins.cpp file.
case 19:
sim1.gpio.pclrr_e = ~0x08;
sim1.gpio.pddr_e |= 0x08;
So in your code you would clear the pin state (Port Clear Output Data Registers) on page 302 of the manual.
Note, this is for clearing the pin only.
sim1.gpio.pclrr_e = ~0x08;
Then set the Port Data Direction Registers for an output as on page 301 on manual.
sim1.gpio.pddr_e |= 0x08;
Note, you probably know this already, once you set the Port Data Direction Registers (sim1.gpio.pddr_x) you do not need to do it again.
There are also other options for the pins like Pull Control Registers, and Port Output Data Registers. you dont have to use pin set and pin clear, you can also set the bit high and low to change its output directly. Each option has its own advantage for speed and so on which all depends on what your trying to accomplish. If you want to know how to talk to these other registers in the manual, then go back to the sim5441x.h file and look from what the manual called it in that struct. So again say we wanted to use the Port Output Data Registers (PODR_x) on page 300 of the manual. well they called it PODR_x. Say want to use Port A. look at that struct and we see NB named it "vubyte podr_a; " so now its a simple matter of using sim1.podr_a
One of the nice things about the software environment is if you see something in the code like "sim1.gpio.srcr_sdhc=0x02;" just put your mouse on it, and press F3 it will take you right to that file so you can see whats going on.
Well, i hope i got you started in making sense of all this. This may not be the "norm" of how to look things up but its how i got used to doing it. The most helpful files to me have always been pins.cpp, pinconstant.h & sim5441x.h
With the manual and these files it has been a much easier way to figure out the peripherals and pins.
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 2:18 pm
by seulater
Sure, that is how i do it, its faster than doing J2[19] = 1;
If i want to control the whole porte at one crack i will do
sim1.gpio.podr_e = 0x00 or sim1.gpio.podr_e = 0xff and so on.
If i want to manipulate one pin i will do one of two things.
#define LCD_CS(x) if(x) sim1.gpio.ppdsdr_d = 0x01; else sim1.gpio.pclrr_d = ~0x01; //PD0
#define LCD_DC(x) if(x) sim1.gpio.ppdsdr_d = 0x02; else sim1.gpio.pclrr_d = ~0x02; //PD1
// These are quicker than above
#define LCD_CS_H sim1.gpio.ppdsdr_d = 0x01; //PD0
#define LCD_CS_L sim1.gpio.pclrr_d = ~0x01; //PD0
Then in the code i just say one or the other.
LCD_CS(1) or LCD_CS(0) or LCD_CS_H or LCD_CS_L, again depending on the speed your after or if you prefer ease of use and code readability. LCD_CS_H & LCD_CS_L is of course going to be faster then LCD_CS(x), but on the other hand LCD_CS(x) is easier to remember for me anyways
Re: MOD54415 GPIO
Posted: Tue Jan 08, 2013 2:42 pm
by jediengineer
You are amazing Sir!! Thank you - As I put in that last response - the C version makes most sense to me. Seeing the switch-case in the pinconstant.h file definitely helped me figure most of it out. Thanks Again!!!
T