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.

Simple GPIO questions



I'm trying to read the buttons on lm4flaunchpad.

I wrote a code like :

// setup

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);

// read

if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0))

   // do something

 

and it is not working. In the same manner i have activated leds and they are working. What am i missing here?

Also i want to ask some other questions:

1- I have seen some functions which have ROM_ version? What is that?

2- I think there is peripheral mapping feature within this mcu. Does it required to be configured of this module for simple digital i/o?

3- I have included "rom.h" file but when i try to access a function declared in that header, i got error which says: "function declared implicitly".

IDE has not problem with this statement : #include "driverlib/rom.h" and no question marks beside it and it can be reached. What may be the problem?

Thanks.

  • Hi,

    The microcontroller used by you has the driverlib ready implemented in a special area in a ROM memory, so you can access all those functions from there, saving your flash space. All these functions are prefixed by ROM_ to know what you call.

    Note also the PF0 pin is default as NMI, so to be used as input you must unlock it. The data sheet details that, but:

    This pin is acted by a mechanical switch, and the TI team provided a special routine to do that (reading a mechanical switch). This is located in drivers/buttons.c file, with some macros defined in buttons.h file. Also the qs-rgb project has a right initialization of this pin and is an example how to use the ButtonsPoll() function provided. Use this function and not direct reading, unless you dismantle the switch and use an electrical pulse instead.

    Petrei

  • Hi,

     

    thanks Petrei for the reply. I saw that example and I'll dig those functions later also i cannot use them because when i try to use ROM version of the PeripheralEnable function, the IDE says it can't find it. It is declared in the rom.h file and i have included it. It's one of my problems. Also i want to use the simple way just to learn something then i'll move on. Does PF4 also require an unlock procedure?

  • Hi,

    As a general procedure, first import the original project and go to Project|Properties - examine all settings, make a picture (use snipping tool) of every tab and then use the resulting document to make replica for a new project. You need some settings in predefined symbols tab: DEBUG, PART_LM4F120XL, TARGET_IS_BLIZZARD_RA1 (check for yourself these...) and some more others. PF4 does not need unlocking.

    Petrei 

  • Petrei said:
    general procedure, first import the original project and go to Project|Properties - examine all settings, make a picture (use snipping tool) of every tab

    Simply outstanding advice - the desire to, "create your own/unique project" over-challenges most - guidance above is solid roadmap toward success.

    The appeal of sub 15USD Stellaris MCU board must be carefully weighed against its 1400+ pg. data manual - and the thick SW-DRL-UG - and a serious read/review of the many code examples w/in StellarisWare.  (perhaps complicated now by its unwanted "yank.")  If still existing - somewhere - consult StellarisWare\Examples\Peripherals - here you'll find a "treasure trove" of tested code - most illuminating.

    However - shortcuts are few - these ARM chips are not for everyone - demand high, ongoing focus/effort. 

    Far less demanding "similar solutions" (i.e. Arduino) are available - you'd do well to "self-assess" prior to moving onward...

  • Since you are familiar to arm and ti mcus, my questions may be seen simple or i may have been seen as lazy or amateur, but believe me you are wrong. I've heavily worked on other structures and with other companies but i'm total stranger to arm and texas mcus and i'm a bit busy right now. I can only spare limited time for this but i steadily go on the subject. Never mind this is not the issue. My purpose or strategy is to go over the concepts and familiarize a bit but not deep until i set some reference points in my head and i have more time and the mcus hit the market and make the way a bit easier to go by light reading, learning what the required documents are, getting familiar to ti's and arm's style and tools, practicing with evaluation boards and with community member helps. Then i'll dive into serious working and began to make projects. As soon as the mcus are out of the production line and hit the market i plan to begin to use them and in time i hope i'll be very comfortable because i like the support and products of TI.

  • Mustafa Gulec said:
    may have been seen as lazy or amateur, but believe me you are wrong.

    No such (personal) suggestion was made - and our group has passed similar advice (where/when warranted) to multiple, large firms.  (having spent time in both law & engineering school - one learns (and tries) to be tactful)  (till provoked beyond reason...)  Choosing the "tool/method" most appropriate to the requirement helped me to co-found - then take past tech firm public...  I try now - w/some regularity - to "give back."

    We do much training - ongoing tech hires - your goal to, "familiarize a bit - but not deep" seems difficult to both define and measure.  (such vagueness may not be "best/fastest" - most considered ticket to success -- our long discovered findings...) 

    Stand behind the applause of Petrei's suggestion - amplified by the further (non-judgemental) and specific guidance I offered. 

     

  • I'm certainly taking the advices seriously that's why I'm asking here. I also appreciated Petrei for his suggestion. But i want to mention also that, especially if you are a trainer, it is also an ability to see through the trainee's eyes; not everybody is same, and making things clear for the person whom you are telling is somewhat difficult and appreciated talent which requires, intelligence, experience, patience and adjusting yourself to the level of the person whom you are relating to. 

  • Mustafa,

    Was your question answered, or do you still need assistance?

    Sheldon

  • Yes i've been able to use buttons, my mistake was using wrong parameter in HWREG() and GPIOPadConfigSet() functions. I must have used "GPIO_PORTF_BASE" as the first parameter instead i used "SYSCTL_PERIPH_GPIOF" and that prevent the buttons work. Now i cannot use ROM_ versions of the functions but I'm on it. Also i was wondering the difference of GPIODirModeSet() and GPIOPinTypeGPIOInput() and GPIOPinTypeGPIOOutput() functions but i saw that gpio.c and similar library functions are open source and i found them and understood. I'll need to get used CCS, project settings, environment variables etc... Thanks.

     

  • At last i made ROM_s work. You are adding to the top of your code this:

     

    #define TARGET_IS_BLIZZARD_RA1

    #include "driverlib/rom.h"

     

    or you are adding

    TARGET_IS_BLIZZARD_RA1 to the pre-defined symbols in arm compiler advanced options and adding

    #include "driverlib/rom.h"

    to the top of your code.

    ;)

  • Hi,

    Maybe the first version works for you, for a particular case of only one file. But the second one is recommended - to say softly, instead "it is a must" since for a project with many files, adding to the predefined symbols apply for all files, instead a single one. Also the linker can use it for libraries. Think about, try to use the second one, for your benefit.

    Petrei.

  • Thanks Petrei,

     

    at first two of the methods worked but now the second one (adding to to the predefined symbols) is stopped working suddenly. CCS behaves as it does not exist. Any clue?

     

    If i add that definition only to the "main.c" properties then it works again but if i add it to the project properties then it does not.

  • Hi,

    In predefined symbols do you have all four defines mentioned in previous post? Include path(s) ok?

    What error(s) are given by the compiler/linker?

    Petrei
     

  • Which four defines?

    I have added "TARGET_IS_BLIZZARD_RA1" to the pre-defined symbols

    and added this into code:

    #include "driverlib/rom.h"

  • Hi,

    In one of  my previous posts I told you:
    " You need some settings in predefined symbols tab: DEBUG, PART_LM4F120XL, TARGET_IS_BLIZZARD_RA1 (check for yourself these...) and some more others. PF4 does not need unlocking."  (and css="css")

    You must adopt the second version (predefined symbols). A stronger reason is the compiler does not accept double/multiple defines for the same symbol - so in project(s) with many *.c files you will get errors if doing otherwise - so the method of predefined symbols must be a habit for you and not an exception.

    Petrei

  • Oh I'm blind , sorry i saw that now. But that was not the problem.... When i accidentally edit main.c properties, general project rules are not applied to the main.c file. So even if i add something to the project predefines, it is not applied to the main.c. I opened main.c properties and clicked "restore defaults" and now all changes are applied to the file and it works again. Thanks for your help.