CorB 64 Posted September 6, 2012 Share Posted September 6, 2012 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 Quote Link to post Share on other sites
Oppa 1 Posted September 6, 2012 Share Posted September 6, 2012 ... 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 ? Quote Link to post Share on other sites
CorB 64 Posted September 6, 2012 Author Share Posted September 6, 2012 GpioCtrlRegs.GPADIR is declared as a LONG and you can adress (this actually works also) for instance GpioCtrlRegs.GPADIR.bit.GPIO17 or GPIO1 ... Quote Link to post Share on other sites
DanAndDusty 62 Posted September 6, 2012 Share Posted September 6, 2012 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); msptest6 and CorB 2 Quote Link to post Share on other sites
CorB 64 Posted September 6, 2012 Author Share Posted September 6, 2012 You are 100% right !!! Thanks. Now I can proceed coding further. Quote Link to post Share on other sites
DanAndDusty 62 Posted September 6, 2012 Share Posted September 6, 2012 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. Quote Link to post Share on other sites
CorB 64 Posted September 6, 2012 Author Share Posted September 6, 2012 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.