yosef 0 Posted April 25, 2014 Share Posted April 25, 2014 I've written a program, which switches the states of the LED when i Press it. It has been programmed so, that it works flawless on the select button on my µC LM3s6965. But when i change the buttons to be one of the other buttons, does the code not work properly. The code i've programmed only works for the select button, but when i choose to use the down,up,right,left button on my board as the input, it does do the same thing as when select was my input.. How come?? I don't understand how changing the input to another button can cause so many issues... Quote Link to post Share on other sites
Lyon 3 Posted April 26, 2014 Share Posted April 26, 2014 Hi, First thing: did you debounced all buttons? Any mechanical switches must be debounced. Second: can you post a code snippet to see where the real problem is? Just "not working" does not say much to think about. L Quote Link to post Share on other sites
yosef 0 Posted April 26, 2014 Author Share Posted April 26, 2014 Here is the code Quote Link to post Share on other sites
yosef 0 Posted April 26, 2014 Author Share Posted April 26, 2014 @@Lyon here is the code Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, The first obvious thing seen from your code is the PF0 needs a special treatment, since this pin is NMI enabled by default, so you must revert it to true GPIO behavior by unlocking it with the following code: HWREG(GPIO_PORTF_BASE+GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE+GPIO_O_CR) |= 0x01; GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0); You can simplify your code - no need for separate timers for each button - just play with all at once and if a button is pressed, just send a message. L Quote Link to post Share on other sites
yosef 0 Posted April 27, 2014 Author Share Posted April 27, 2014 @@Lyonwell it is POrt E , and I don't quite understand what you are doing??it won't add the function... i was thinking about the code itself. Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, OK, my misunderstanding, due to this line: // Enable the GPIO pins for digital function (PF0). About your code - I have doubts it works correctly - once the "state" variable is set up, the other cases do not check other buttons - maybe removing the break statement will restore the whole scanning (or better to think different and re-write this task). L Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, If you use the development board, the buttons are placed on PE0…PE3, but you changed from PE1… maybe is a custom board... Try this in your initialization: // // Configure the GPIOs used to read the state of the on-board push buttons. // GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); L Quote Link to post Share on other sites
yosef 0 Posted April 27, 2014 Author Share Posted April 27, 2014 no it is the dev board. I am using PE1, PE2, PE2 and PF1 actually. I am having some problems with the PF1 now. Please look at the my edit. above. @@Lyon Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, To initialize PF1: GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); And yes, you may have problem(s) scanning... L Quote Link to post Share on other sites
yosef 0 Posted April 27, 2014 Author Share Posted April 27, 2014 But how can i get rid of it... I use the same code for detecting, but for some reason it works better on some keys than others. Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, I understand - first step is to use a uniform timing for all switches - and only one timing, not separate times for each switch. I presume you got into this by the fact you have to scan PF1 which is on separate port. But I think there is a possibility to manage that - allow me some time to think. Also you can reduce the scanning interval - 100 ms is too much - 10 ms would be better, since actual switches need only 1 ms debuncing time (data sheet). L Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, Read this - is an excerpt from the application qs_ek-lm3s6965.c file: // // Read the state of the push buttons. // ulData = (GPIOPinRead(GPIO_PORTE_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3)) | (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1) << 3)); // // Determine the switches that are at a different state than the debounced // state. // ulDelta = ulData ^ g_ucSwitches; // // Increment the clocks by one. // g_ucSwitchClockA ^= g_ucSwitchClockB; g_ucSwitchClockB = ~g_ucSwitchClockB; // // Reset the clocks corresponding to switches that have not changed state. // g_ucSwitchClockA &= ulDelta; g_ucSwitchClockB &= ulDelta; // // Get the new debounced switch state. // g_ucSwitches &= g_ucSwitchClockA | g_ucSwitchClockB; g_ucSwitches |= (~(g_ucSwitchClockA | g_ucSwitchClockB)) & ulData; // // Determine the switches that just changed debounced state. // ulDelta ^= (g_ucSwitchClockA | g_ucSwitchClockB); // // See if any switches just changed debounced state. // if(ulDelta) { I think this is best to do - and when changes are detected just send messages as you wish. L Quote Link to post Share on other sites
yosef 0 Posted April 27, 2014 Author Share Posted April 27, 2014 I don't quite understand your codesnippet... Could you explain?? Those variables what do they indicate? Quote Link to post Share on other sites
Lyon 3 Posted April 27, 2014 Share Posted April 27, 2014 Hi, This code is part of application qs_ek-lm3s6965 - it uses a sys timer interrupt at 10 ms to make several things, including scanning all switches. You may read the .c file for all variables declared there and their meaning. Mainly it uses a static variable and a temporary one; XORing both determines if a switch was pressed or not. ulData is the state of switches - please note how different ports (E and F) are read and mixed to have all five switches info in a single variable. The last ulDelta has a 1 for a pressed switch ( inverted info in previous stages, since the real info is a 0 ) - and from there it is easy to manage them - hope this will help you. L 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.