Page 1 of 1

MOD54415 GPIO confusion

Posted: Mon Jan 21, 2013 1:04 pm
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?

Re: MOD54415 GPIO confusion

Posted: Mon Jan 21, 2013 4:44 pm
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.

Re: MOD54415 GPIO confusion

Posted: Mon Jan 21, 2013 6:43 pm
by Ridgeglider
Got it, Thanks Tod. Now I see where the J1, J2, and Pins objects are setup too.

Re: MOD54415 GPIO confusion

Posted: Tue Jan 22, 2013 6:27 am
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?

Re: MOD54415 GPIO confusion

Posted: Tue Jan 22, 2013 8:12 am
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.

Re: MOD54415 GPIO confusion

Posted: Tue Jan 22, 2013 10:06 am
by jediengineer
Thanks for all the help!! I got it!