LadyInRed 0 Posted April 16, 2014 Share Posted April 16, 2014 Hi. I want to made a simple program who turn on/off a led. In the function below i must use the XOR operator in line : GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 8); How can i write the XOR operation ? void Timer0BIntHandler() { TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); counter++; if(counter == NUMBER_OF_INTS) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 8); counter = 0; } } Quote Link to post Share on other sites
Lyon 3 Posted April 16, 2014 Share Posted April 16, 2014 Hi, As far as I know, a LED has only one pin to act on (beside the other which is at fixed potential, either Hi or Lo) - why do you "must" and on what pin is the LED mounted on? what about the other pins in your expression? L Quote Link to post Share on other sites
pabigot 355 Posted April 16, 2014 Share Posted April 16, 2014 I don't believe driverware provides an API that supports XOR, only setting or clearing all the specified pins. The following hack will invert all three LEDs on the ek-tm4c123gxl in one step: ((uint32_t *)GPIO_PORTF_BASE)[GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3] ^= ~0; or the equivalent: HWREG(GPIO_PORTF_BASE + (GPIO_O_DATA + ((GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3) << 2))) ^= ~0; which uses material from <inc/hw_types.h> and <inc/hw_gpio.h> and is closer to how GPIOPinWrite() is implemented. Quote Link to post Share on other sites
Lyon 3 Posted April 17, 2014 Share Posted April 17, 2014 Hi, Here is my solution, for changing pins 1 and 2. Adapt for your case: static uint8_t ledonoff; GPIOPinWrite(GPIO_PORTF_BASE, \ (GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3), \ ledonoff^=(GPIO_PIN_1 | GPIO_PIN_2)); L Quote Link to post Share on other sites
LadyInRed 0 Posted April 18, 2014 Author Share Posted April 18, 2014 I found a solution : void Timer0BIntHandler() { TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); COUNTER++; GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, LED); if(COUNTER == NUMBER_OF_INTERRUPTS) { LED ^= 0x08; COUNTER = 0; } } Quote Link to post Share on other sites
LadyInRed 0 Posted April 18, 2014 Author Share Posted April 18, 2014 Where LED = 0x08; void Timer0BIntHandler() { TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT); COUNTER++; GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, LED); if(COUNTER == NUMBER_OF_INTERRUPTS) { LED ^= 0x08; COUNTER = 0; } } Quote Link to post Share on other sites
spirilis 1,265 Posted April 18, 2014 Share Posted April 18, 2014 Yup that works. Quote Link to post Share on other sites
pabigot 355 Posted April 18, 2014 Share Posted April 18, 2014 Agreed, that works, assuming LED is a statically allocated variable and nothing else changes either it or the corresponding pin's output value. I dislike caching a last-known state when the actual current state can easily be read, but that's a combination of personal choice and the application requirements. Quote Link to post Share on other sites
Rickta59 589 Posted April 18, 2014 Share Posted April 18, 2014 The GPIO peripherals on some other brands of ARM controllers (NXP LPC8xx chips come to mind) have a register that lets you toggle pins atomically by setting a register. See the NOT0 register on page 91 for details: http://www.nxp.com/documents/user_manual/UM10601.pdf I tried to find something like this for the TI chip but nothing jumped out at me. -rick 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.