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.

problem in gpio api



Hi,

I am newbie to ti .I am using stellaris lm4f232h5qd evaluation kit .i was  able to run the example blinky project successful and tried myself to use gpio api function by simply delete blinky .c code line and added the code given below is to turn on the user led (port g ,pin 2 ) is build without error , while debugging i found that  GPIOPinTypeGPIOOutput  function calls 

GPIOPadConfigSet function in this fuction  when it enters the code  line

HWREG(ulPort + GPIO_O_DR2R) = ((ulStrength & 1) ?
// (HWREG(ulPort + GPIO_O_DR2R) | ucPins) :
// (HWREG(ulPort + GPIO_O_DR2R) & ~(ucPins)));

it calls to fault ISR  routine . it will be immense help for me if you guide me on this 

my actual code is

#include "driverlib/gpio.h"
#include "driverlib/gpio.c"
void main()
{
GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
while(1)
{
GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_0,0xFF);
}
}

regards,

Tamil vanan 

  • You should not: #include "driverlib/gpio.c" - nor any other of the driverlib C functions.

    Look at the more involved code examples provided - you will see other .h files such as hw_gpio.h, pin_map.h, and lm_xxxx.h.   Your program is faulting as it cannot find a needed function or  parameter.

    Don't agree that "immense help" results from fixing this limited piece of code.  Suggest instead that you review several of the other supplied code example projects - look carefully at the includes and declarations - this will shed much light on how a program, "goes together." 

  • Most likely your code is faulting because you are not initializing the GPIO peripheral properly.  first you need to enable clocking to the peripheral.  If you do not enable clocking to the peripheral, any access to its registers will cause a fault.

    Additionally, your code sets pin 2 to be an ouptut, but then in your loop you don't write to pin 2, but to pin 0.  That discrepancy won't cause a fault, but it will keep you from getting the behavior you want.

  • Any access to a peripheral that you have no enabled will generate a fault. If you add a line at the top of main that enables GPIO port G, I bet you find your problem goes away.

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

    You should find this in every example we include. Blinky is a special case since it doesn't use DriverLib. The equivalent there is:

    SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOG;

    Personally, I would recommend using DriverLib over direct register access but, regardless of which you choose, I would suggest you stick to a single model and don't try to mix the two.

  • Hi

    Thanks for your  valuable replies.It encourages me learn ti controllers .After adding SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);  my code works fine. I have few questions with my working code shown below.

    ...........................................................................................................................................................................................................................................................................................................

    #include "driverlib/gpio.h"
    #include "driverlib/gpio.c"
    #include "driverlib/sysctl.h"
    #include "driverlib/sysctl.c"
    void main()
    {

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
    while(1)
    {
    GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_2,0xFF);
    }
    }

    ...............................................................................................................................................................................................................................................................................................................

    1) in my code i have included the gpio.c(apifuctions.c) directly .If it's not advisable means ,please suggest me the solution

    2) i just simply deleted blinky.c  and added above code ,when i try to create my own project with startup_css.c, macro.in_intial  copied from blink led but it not works ,instead it shows  the following  error

    undefined first referenced
    symbol in file
    --------- ----------------
    CPUwfi ./main.obj
    IntDisable ./main.obj
    IntEnable ./main.obj
    IntRegister ./main.obj
    IntUnregister ./main.obj
    SysCtlDelay ./main.obj

    3) i have no idea about startup_ccs.c ,macro.in_initial and blinky.cmd  

    please guide me on this 

    Regards,

    Tamil Vanan K.

  • tamil vanan said:
    have included the gpio.c

    Your, #include "driverlib/gpio.h" is sufficient to engage the content of gpio.c.  (it is bad form to #include any of the driverlib .c files - not just gpio.c)  Remove #include gpio.c - your code will still run.

    Believe you are far better served to AVOID the urge to, "create your own project!"  This usually causes pain and suffering - guaranteed to delay your progress.  (and is true across most all IDEs - not just CCS)  Instead - far better (our group/others have found) is to find some existing TI project (closest to yours) and slowly, methodically add your changes and experiments.  TI provided projects are well established - have proven sound - and you can modify them (carefully) as you see fit.  Starting from something, "Known Good" provides you a powerful advantage - "creating your own" - not so much...

    Our belief is that you should be learning about the MCU - its many features - and the power of good programming.  Mastery of any IDE "ins/outs" should not be SO compelling!

  • Hi

    Thanks everyone for your valuable suggestion . It will helpful for me , if i get answers for my questions in previous post' which i added below , I feel like once i start able to create small program of my own , it will easy implement my ideas,

    **************************************************************************************************************************************************************************************

    Hi

    Thanks for your  valuable replies.It encourages me learn ti controllers .After adding SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);  my code works fine. I have few questions with my working code shown below.

    ...........................................................................................................................................................................................................................................................................................................

    #include "driverlib/gpio.h"
    #include "driverlib/gpio.c"
    #include "driverlib/sysctl.h"
    #include "driverlib/sysctl.c"
    void main()
    {

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
    while(1)
    {
    GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_2,0xFF);
    }
    }

    ...............................................................................................................................................................................................................................................................................................................

    1) in my code i have included the gpio.c(apifuctions.c) directly .If it's not advisable means ,please suggest me the solution

    2) i just simply deleted blinky.c  and added above code ,when i try to create my own project with startup_css.c, macro.in_intial  copied from blink led but it not works ,instead it shows  the following  error

    undefined first referenced
    symbol in file 
    --------- ----------------
    CPUwfi ./main.obj 
    IntDisable ./main.obj 
    IntEnable ./main.obj 
    IntRegister ./main.obj 
    IntUnregister ./main.obj 
    SysCtlDelay ./main.obj

    3) i have no idea about startup_ccs.c ,macro.in_initial and blinky.cmd  

    please guide me on this 

    Regards,

    Tamil Vanan K.

  • Hi, 

    It seems you don't want to follow the good advises posted for you - why?

    Here it is a document describing "how-to" for a new project. Just follow it ad -literam.

    4774.Stellaris_New_Project_Guide.pdf 

  • Petrei said:
    seems you don't want to follow the good advises posted

    I'm confused - seems that you 1st agree with, "stick to MCU basics - not IDE" - and then quickly encourage, "study the IDE!" 

  • Dear forum people,

    I thank everyone for  spending your valuable  time to reply .Now i have done my own simple led on program using gpio api  . It really encourages me  to learn a lot once again thanks for your continues support

    Regards,

    Tamil vanan K