Jump to content
43oh

Recommended Posts

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;

        }

}

Link to post
Share on other sites

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.
Link to post
Share on other sites

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
Link to post
Share on other sites

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;
        }
}
Link to post
Share on other sites

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;
        }
}
Link to post
Share on other sites

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.

Link to post
Share on other sites

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

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...