Pradeepa 1 Posted April 8, 2013 Share Posted April 8, 2013 I am a newbie to Stellaris. I have a LM4F120H5QR launchpad with me. I just want to poll a switch and at least turn on an LED. all i want to do is: if(button pressed){ turn on the led; } For this do I need to use the ButtonPoll() API as per the Lab3 of the stellaris wiki. I cannot really understand the code much, i mean i know what bouncing is but i did not see how they actually poll the switch in the buttons.c. For example what is that g_s_Appstate or something which is there in the code. Please help me. Quote Link to post Share on other sites
bluehash 1,581 Posted April 8, 2013 Share Posted April 8, 2013 Could you post the code here? Quote Link to post Share on other sites
Pradeepa 1 Posted April 9, 2013 Author Share Posted April 9, 2013 Could you post the code here? Which code? I want to know how to poll a switch using LM4F120H5QR... Quote Link to post Share on other sites
bluehash 1,581 Posted April 9, 2013 Share Posted April 9, 2013 The code which Lab3 uses. I have not worked with the labs. Quote Link to post Share on other sites
Pradeepa 1 Posted April 9, 2013 Author Share Posted April 9, 2013 Lab3 code has nothing to do with this. They simply asks us to write a program using Buttons.h API to switch on an LED. #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "buttons.h" int main(void) { unsigned char button_val; unsigned char Delta; SysCtlClockSet(SYSCTL_SYSDIV_5| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE , GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); ButtonsInit(); while(1){ SysCtlDelay(100000); button_val = ButtonsPoll(Δ, 0); } } This is my code so far. This will not compile. Errors: Description Resource Path Location Type unresolved symbol ButtonsPoll, first referenced in ./main.obj Lab3HW C/C++ Problem unresolved symbol ButtonsInit, first referenced in ./main.obj Lab3HW C/C++ Problem #10010 errors encountered during linking; "Lab3HW.out" not built Lab3HW C/C++ Problem <a href="file:/C:/ti/ccsv5/tools/compiler/dmed/HTML/10234.html">#10234-D</a> unresolved symbols remain Lab3HW C/C++ Problem I just want to know how to use buttons.h in the correct way. Quote Link to post Share on other sites
bluehash 1,581 Posted April 9, 2013 Share Posted April 9, 2013 Where is buttons.h defined? In you current folder or another subfolder. Zip your project up and attach it here. Quote Link to post Share on other sites
Pradeepa 1 Posted April 9, 2013 Author Share Posted April 9, 2013 Where is buttons.h defined? In you current folder or another subfolder. Zip your project up and attach it here. The button.h is defined in another location in my hard disk. I added the include path. https://dl.dropbox.com/u/81891666/Lab3HW.7z this is the link to the zip file Quote Link to post Share on other sites
bluehash 1,581 Posted April 9, 2013 Share Posted April 9, 2013 Change in buttons.c file #include "drivers/buttons.h"to #include "buttons.h" Quote Link to post Share on other sites
Pradeepa 1 Posted April 10, 2013 Author Share Posted April 10, 2013 It didn't work. Stellaris ware qs-rgb example uses this ButtonPoll() thing. I don't know how it is working. I included buttons.h and i included the path too. But somehow the linker cannot resolve symbols it seems. What can I do? Quote Link to post Share on other sites
bluehash 1,581 Posted April 10, 2013 Share Posted April 10, 2013 Did you do a clean and rebuild? Quote Link to post Share on other sites
Pradeepa 1 Posted April 11, 2013 Author Share Posted April 11, 2013 I cleaned and rebuilt it. Now i get the following errors. Description Resource Path Location Type unresolved symbol ROM_GPIODirModeSet, first referenced in ./drivers/buttons.obj Lab3HW C/C++ Problem unresolved symbol ROM_GPIOPadConfigSet, first referenced in ./drivers/buttons.obj Lab3HW C/C++ Problem unresolved symbol ROM_GPIOPinRead, first referenced in ./drivers/buttons.obj Lab3HW C/C++ Problem unresolved symbol ROM_SysCtlPeripheralEnable, first referenced in ./drivers/buttons.obj Lab3HW C/C++ Problem <a href="file:/C:/ti/ccsv5/tools/compiler/dmed/HTML/10234.html">#10234-D</a> unresolved symbols remain Lab3HW C/C++ Problem #10010 errors encountered during linking; "Lab3HW.out" not built Lab3HW C/C++ Problem Quote Link to post Share on other sites
Pradeepa 1 Posted April 11, 2013 Author Share Posted April 11, 2013 This is something i just discovered which might shed some light on the overall picture. Just now i navigated to the rom.h under includes from the project explorer. I found out that the functions inside the Rom.h file looks disabled. With faded blue color. https://dl.dropboxusercontent.com/u/81891666/error.JPG But in qs-rgb.c file which actually is an example that uses this Button.h i found that those functions looks enabled. With dark blue color. Quote Link to post Share on other sites
Lyon 3 Posted April 11, 2013 Share Posted April 11, 2013 Hi, It would be useful to know what tools do you use (CCS/other?) I will assume CCS. The ButtonsPoll function must also be part of your project - so just #include drivers/buttons.h will not suffices. Add to the project the path to this file (in Include paths). Add the file buttons.c to your project, as a symbolic link; this way it will be part of the project, compiled and the linker will find out the code of this function. Do not forget to call also ButtonsInit() before using ButtonsPoll() (yes, you did it..). Now, still for CCS, but should be done for other tools: to the Compiler | preprocessor add the followings defined macros: DEBUG PART_LM4F120H5QR TARGET_IS_BLIZZARD_RA1 (this will solve the ROM_xxx complaints..) Lyon bluehash and Pradeepa 2 Quote Link to post Share on other sites
cosscat 0 Posted April 12, 2013 Share Posted April 12, 2013 Hello Friend, Try out this code. It will clarify a lot your questions: #include "inc/hw_gpio.h" #include "inc/hw_memmap.h" #include "inc/hw_sysctl.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/sysctl.h" #define LED_RED GPIO_PIN_1 #define LED_BLUE GPIO_PIN_2 #define LED_GREEN GPIO_PIN_3 #define BUTTON_1 GPIO_PIN_0 #define BUTTON_2 GPIO_PIN_4 void main(void) { int light; // configure system clock to run at 50 MHz // use external crystal (16 MHz) and PLL SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); // Enable PORT F GPIO SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; // set LED pins as outputs GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); // SEE COMMENTS IN THE POST // set user switches as inputs GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, BUTTON_1|BUTTON_2); // turn weak pull-ups on GPIOPadConfigSet(GPIO_PORTF_BASE, BUTTON_1|BUTTON_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // loop forever for (; { light = 0; if(!GPIOPinRead(GPIO_PORTF_BASE, BUTTON_1)) light |= LED_RED; if(!GPIOPinRead(GPIO_PORTF_BASE, BUTTON_2)) light |= LED_BLUE; GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN, light); SysCtlDelay(500000); } } It is derived from a post found on the internet and also a search in buttons.h and buttons.c under StellarisWare directory . Costin, Pradeepa 1 Quote Link to post Share on other sites
Pradeepa 1 Posted April 13, 2013 Author Share Posted April 13, 2013 Add the file buttons.c to your project, as a symbolic link Dear Lyon, Can you explain me how to do this. I don't know about the symbolic link. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.