This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPIO basic question

Other Parts Discussed in Thread: TM4C123GH6PM

Hi,

I have the following code: (It's part of the bigger piece of course)

GPIO_PORTD_DIR_R = 0x02;                    // PD1 is an output
GPIO_PORTD_AFSEL_R &= ~0x02;      // regular port function
GPIO_PORTD_AMSEL_R &= ~0x02;      // disable analog on PD1 (TM4C)
GPIO_PORTD_PCTL_R &= 0x000000F0;  // PCTL GPIO on PD1 (TM4C)
GPIO_PORTD_DEN_R |= 0x02;         // PD1 is enabled as a digital port
PD1 = 0x02;                       // make PD1 high
PD1 = 0x00;                       // make PD1 low
 
This code works and operates PD1. However, what if I want to operate PD2 or PD3 or all of them at once what values I pass then. Is there a document that describes this? What values I pass to make PDx high/low is this always 0x02 and 0x00?
I know it is basic stuff but I am new to embbeded programming and I need to start somewhere.
 
Thank you
Marcel
  • Hi Marcel,

         See, GPIOPinWrite() at the Tivaware Peripheral Drivers Library Users Guide. 

    -kel

  • hii markel

    highlighted piece of code is not working. please have a look.


    #include<tm4c123gh6pm.h>
    #include<stdbool.h>
    #include<stdint.h>
    #include<interrupt.h>
    #include<sysctl.h>
    #include<gpio.h>
    #include<hw_memmap.h>
    #include<timer.h>

    volatile unsigned long u,p,q;
    void delay(int a);
    int main(void)
    {
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlDelay(3);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlDelay(3);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_6|GPIO_PIN_7);

    while(1)
    {
    q= GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_7)& 0x80;
    p= GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_6)& 0x40;
    if(p==0x40) //button pressed
    {
    GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,true);
    delay(300000);
    GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,false);
    delay(300000);
    }
    else if(q==0x80) //button pressed
    {GPIO_PORTD_DATA_R |= 0x02;
    delay(300000);
    GPIO_PORTD_DATA_R &= ~(0x02);
    delay(300000);
    }

    else //button not pressed
    {
    GPIO_PORTD_DATA_R |= 0x08;
    delay(300000);
    GPIO_PORTD_DATA_R &= ~(0x08);
    delay(300000);
    }
    }
    }
    void delay(int a){
    for(u = 0; u < a; u++)
    {}}

    regards

    prashant