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.

input switch code in tm4c123gh6pm

Hi, 

i want to configure switch in PORT F  PIN 0 as a user defined switch.

i have pasted the code below,(its not working), what change i need to do in the code below

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"

/////////Peripheral Header File
#include "driverlib/gpio.h"


int main(void)
{
	 SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	 GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
	 GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
	 GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1);


    while(1)
    {
    	if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0)
    		{
    		while(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0)
    				{
    				GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,GPIO_PIN_1);
    				}
    				}
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
    			}

    }

  • Hi Haresh,

         See, ISSUE#1 from the link below.

         Diagnosing Common Development Problems and Tips for TM4C Devices

    - kel

  • Appears that neither the "signature block" nor the top forum sticky - prove especially effective in preventing the (unending) plight of new users...

    Some achieve forum status by (primarily) answering such repetitive posts.  

    Might - instead - forcing Amit (alone) to respond lead to the (long needed) correction - rather than the ineffectual, "one and done" (then lost forever) "bandaid responses" we lowly outsiders may provide...  (upon seeing this post earlier - just after we commented upon "differential ADC" one of the young staff asked, "How long before Markel arrives?")

  • cb1_mobile said:
    just after we commented upon "differential ADC" one of the young staff asked, "How long before Markel arrives?")

     Sorry, but my first professional has something to do with answer, arrive to do what?

     No special problem from port is in place and again this appear as a simple beginner raised to guru level..

     I PROPOSE AGAIN SPLIT FORUM AND EXAM TO RAISE LEVEL!!!!!

     If Markel don't pass can be happy answer lot of this question instead of useful question with silly answer and leave professional where we wish share production and REAL issue problem share than scream about new kid role of toy is not working. Also when they buy professional software kit they generally scream this is not working... real question they are not able to develop code itself, buy a developing kit and pretend simple example fit his need then scream software doesn't work and as I wrote pretend professional firm seller develop his code for free.

     It is time to stop this bad habit!!!

  • Haresh G said:
    int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1); while(1) { if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0) { while(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0) { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,GPIO_PIN_1); } } GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0); } }

    int main(void) 
    {
     SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
     GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
     GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
     GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1);
    
     while(1)
     {
       if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0)
       { 
          while(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0)==0)
          {
             GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,GPIO_PIN_1);
          }
       }
       GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
     }
    }

     So this quite useless code can be changed to :

     while(1)
    
       if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0))
    
           GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,0);
       else
           GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,GPIO_PIN_1);
    
    
    

    what is not working in this so complex expensive inverter gate???

  • @ Roberto,

    Issue here is the dreaded "NMI as default" which inflicts poster's PF0.   This has persisted for over two years now - I answered these when they first were noted - then advised hallowed vendor to invest in some "real fix."  One suggestion was bright red notice - Page 1 - each MCU manual.  (some red ink may remain from the pool of ink which splashed across each/every LM3S manual - proclaiming NRND!)

    Better still - kill that "NMI as default" - replace w/far more normal "GPIO as default" and (only) force "special handling" on those (FEW) who may employ NMI.  But - that's too obvious - too simple - and NIH...

    Alas - while "duly noted" - issue has remained, "duly ignored."  Top sticky post has too vague a title - and which rushed new user would think to go there?

    By arrive - we knew that one forum user would "seize" upon this repetitive issue - while the more complex, instructive posts are, "passed."

  •  @ Amit, on first forum post please edit this from

    3. The Decap on VDDC should be in the range of 2.2uF to 4.7uF

    in

    3. The Decaps on (every) VDDC MUST be in the range of 2.2uF to 4.7uF total capacitance.

     @CB1

    cb1_mobile said:
    Issue here is the dreaded "NMI as default" which inflicts poster's PF0.

     No change in where none read nothing and then ask for, we forever have people first post than read, none again seems to read the following post on how to ask forum help...

     Uhm.. NMI I don't remember I used it, unsure maybe a very long time ago saving working parameter to battery backed ram. Maybe in some early processor but I never find it of primary importance before now it need to be changed from primary to GPIO in dead Stellaris and TIVA. We hope have GPIO default on new series or silicon revision to save code and effort.

     A voting request for who use it can be useful to see how many but now problem is on the road and cannot be forgot without ISR faulting too!