Jump to content
CorB

SOLVED :Code issues: automated setting of GPADIR for GPIOpins >15 problematic

Recommended Posts

Hi all,

 

I am developing a simple codelibrary that should make setting the pins for input/output of the C2k launchpad easier. I am using definitions for the pins that correspond to the physical pinnumbers on J1/J2 and J5/6. So a user can set pin J2_2 as output without a need to think if this pin is a real GPIO or an ADCpin.

 

I am running however into problems with the piece of code below:

 

if (pinmode==GPIO_Direction_Output)
{ GpioCtrlRegs.GPADIR.all |= (1<<pinNumber); // set the pin to output, set bit=1
}
else

{ GpioCtrlRegs.GPADIR.all &= ~(1<<pinNumber); // set the pin to input, set bit=0
}

pinNumber corresponds to the normal GPIOnumber of any pin, pinmode simply represets 0=input or 1=output.

 

When I call this code with pinNumber=17 and pinmode=1, GPIO1 gets set for output instead of GPIO17. I first had pinNumber declared as an uint16_t variable, changed that into uint32_t variable but the problem remained the same ...

 

Anybody with a clue as to why I am running into this limitation ?

For GPIO0 -GPIO15 the code works as planned ...

 

regards

Cor

Share this post


Link to post
Share on other sites

...

Anybody with a clue as to why I am running into this limitation ?

For GPIO0 -GPIO15 the code works as planned ...

Just a guess, is this register only 16 bit wide ?

Share this post


Link to post
Share on other sites

GpioCtrlRegs.GPADIR is declared as a LONG and you can adress (this actually works also) for instance GpioCtrlRegs.GPADIR.bit.GPIO17 or GPIO1 ...

Share this post


Link to post
Share on other sites

I don't have access to my dev terminal here at the moment.. But I seem to remember hitting something similar on a different processor a while ago. Does it work if you cast the 1? I.E.

 

GpioCtrlRegs.GPADIR.all |= ((unsigned long)1<<pinNumber);

Share this post


Link to post
Share on other sites

You are 100% right !!! Thanks. Now I can proceed coding further.

 

Cool, Glad it worked.. I only came back because I remembered that there is another way.. Instead of the cast you can add UL to the end.. Which is clearer is up to you.. but 1UL << pinNumber should also work.

Share this post


Link to post
Share on other sites

Hi,

 

Ive allread updated the code - see other message in this forum - using your original suggestion. Sometimes you can do a lot of searching for things that arent obvious ! Now we can easily set any of the connectorpins high/low etc without the need to know if the pin is GPIO or ADC and without the need to know which GPIO/ADC is connected to which pin. Now you just state OutputPin(J2_10) and pin 10 on connector 2 will be prepared for output.

 

cheers

 

Cor

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...