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.

Controlling Port K for GPIO outputs on EKS-LM4F232 using Keil uVision4

Here's my code.

I want to control GPIO Port K Pin 4 on EK-LM4F232 Board.

But I got 0V using this code...

How can I get high voltage rather than 0 V?

    // Enable GPIO Port K.
      //
      SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
        
        // Configure GPIO pins as output.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_4);
        
        GPIOPadConfigSet (GPIO_PORTK_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        
        GPIOPinWrite (GPIO_PORTK_BASE, GPIO_PIN_4, 0x02);

  • jeff Cheng said:
    GPIOPinWrite (GPIO_PORTK_BASE, GPIO_PIN_4, 0x02);

    And you chose the value 0x02 by what methodology?  Unless this particular pin defaults into some strong, alternate function - proper load of final parameter (0x10) should produce your desired output high...

  • Thanks!!

    I just don't know how to choose the value in the case for output high at GPIO Port, so I try 0x00, 0x01, 0x02 etc....

  • Jeff,

    Each bit in the hex byte that you pass to the function corresponds to a pin on the port. For example, if you want pin 4 to go high, pass a 0x10 (00010000 in binary). If you want pin 7 to go high, pass 0x80 (10000000 in binary). If you want both pin 4 and 7 high, pass 0x90 (10010000 in binary). If you want to things to be more obvious at the cost of longer code, you can use GPIO_PIN_4 | GPIO_PIN_9 GPIO_PIN_7 (thanks cb1 for the heads up!) in place of the hex byte to accomplish the same thing.

  • cb1_mobile said:
    proper load of final parameter (0x10) should produce your desired output high...

    Ah - repetition is indeed sincerest form of flattery.  (and should warrant favored Verify Answer fm TI - poster too new to know...)

    But mystery remains - poster complained NOT about all other Ports/Pins - so what's up w/ this one?  And that's the real issue!

  • Stellaris John said:
    you can use GPIO_PIN_4 | GPIO_PIN_9

    Perhaps not!  While certain ARM MCUs support 16 bit D-Bus transfers (w/o external bus) Stellaris not yet there - thus all standard Stellaris Ports "max out" @ GPIO_PIN_7.

  • Thanks both cb1_mobile and .

    I just want to use GPIO port K pin 4 to 7 on this board, they will be "High" to enable other chips, and "Low" to disable them.

    Thanks for answering and explaining the hex byte passing to the function.

  • And thanks to you too - Mr. Cheng.  (Verify Answer always nice reward)

    Please review the GPIO chapter in your MCU datasheet (I know - so many pages!)  You can avoid much trouble if you pay special attention to Port C - as its 4 low-order pins (PC0-PC3) also serve JTAG programming/debug function.  Should you mistakenly program even 1 of these - you will lose JTAG communication with your board!  (there is an involved procedure to "recover" - but wastes time/effort - far better to avoid.) 

    Fore-warned is fore-armed - good luck...

  • Thanks for your warning about Port C!! I finally realize what the value passing to the function means, so I change it.

         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
         GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_4);
         GPIOPinWrite (GPIO_PORTK_BASE, GPIO_PIN_4, GPIO_PIN_4);

    It works. Thanks a lot !! The information is very helpful for me!!

  • Excellent - looks like you're well on your way!  As to Port C - I always advise young/new staff to keep an index card - high-lighted in RED - @ their PC - warning about Port C.

    Your GPIO_PIN_4 certainly works - and is recommended.  (saves "hex conversion in your head" errors)  However - sometimes you will want to read/write to an entire 8 bit Port.  (such as when writing to Text or Graphic Lcd.)  Now - to write to a port you can first define a "char" and then use: char = 0xAB; and then you can use your GPIOPinWrite() with the 2nd parameter set to 0xFF (all bits potentially enabled) - and then use char as final parameter.

    thus:  GPIOPinWrite(GPIO_PORTK_BASE, 0xFF, char);  //  this will cause Port K to emit the value contained w/in variable char - which should prove very useful...  One caution - with 2nd parameter set as shown (0xff) you are vulnerable to unwanted bit outputs from Port K - should you make a mistake with the 3rd parameter!  That 2nd parameter can be thought of as a logical "qualifier" - only Port bits included w/in parameter 2 - may appear/be processed at that Port's pins.  (works same send and receive...)

    Good luck...