MOD54415 GPIO confusion

Discussion to talk about software related topics only.
Post Reply
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

MOD54415 GPIO confusion

Post by jediengineer »

Hi all, if I have the following code to set up my GPIO:

const BYTE J1_PinNum[7] = { 5, 6, 7, 9, 10, 13, 31 }; // GPIO pins on J1
const BYTE J2_PinNum[17] = { 21, 22, 27, 30, 31, 32, 33, 34, 35, 36, 37, 40, 41, 42, 44, 47, 48 }; // GPIO pins on J2

for ( int i = 0; i < 7; i++ )
{
J1[J1_PinNum].function(PIN_GPIO); // Sets All J1 GPIO pins as GPIO
}
for ( int i = 0; i < 18; i++ )
{
J2[J2_PinNum].function(PIN_GPIO); // Sets all J2 GPIO pins as GPIO
}

Do I further need to define the pins as an input (all these are inputs) and if yes, how?
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: MOD54415 GPIO confusion

Post by tod »

You can look at the pins.cpp file under C:\nburn\MOD5441X\system to get most any answer. What you see in this regard is when you write using the class it sets the data direction register with each write. When you read it sets it for each read. If you're only setting things up with the pins class and you're going to read and write directly to the sim address then I believe the data direction register defaults to reading and you have to explicitly set it only when writing.
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: MOD54415 GPIO confusion

Post by Ridgeglider »

Got it, Thanks Tod. Now I see where the J1, J2, and Pins objects are setup too.
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 GPIO confusion

Post by jediengineer »

Thanks for the info - I think I understand... Sorry - I'm still new to C and C++, kind of got thrust into programming and having to learn on the fly... so really, they'll be fine set up that way? And the OS will determine if I'm trying to read and write - If I understand you correctly?
User avatar
dciliske
Posts: 624
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: MOD54415 GPIO confusion

Post by dciliske »

To answer the question, if you're using the PinIO class (aka J1[n] or J2[n]), then those will automagically set the pin direction. Basically the class overloads operator=() and int() so that assigning a value to the pin (say, J2[30] = 1) will put the pin in output mode and drive the pin (high in this case), and using the object to assign to an int (or where an int can be cast) will set it input mode and read the value.
Dan Ciliske
Project Engineer
Netburner, Inc
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 GPIO confusion

Post by jediengineer »

Thanks for all the help!! I got it!
Post Reply