Page 1 of 2
checking the value on a pin
Posted: Wed Jul 25, 2012 8:52 pm
by ganeshredcobra
Hello am using stm32f4 discovery board along with chibios.... i need to check whether the value of that pin is high or low.....
i need to know how can check that condition in chibios...
Re: checking the value on a pin
Posted: Wed Jul 25, 2012 9:02 pm
by Giovanni
Hi,
It is palReadPad(), there is an example in main.c into the STM32F4-Discovery demo, it checks the button state:
/*
* If the user button is pressed after the reset then the test suite is
* executed immediately before activating the various device drivers in
* order to not alter the benchmark scores.
*/
if (palReadPad(GPIOA, GPIOA_BUTTON))
TestThread(&SD2);
The pin must be programmed as input of course.
Giovanni
Re: checking the value on a pin
Posted: Thu Jul 26, 2012 6:53 am
by ganeshredcobra
Thank you will check that

Re: checking the value on a pin
Posted: Thu Jul 26, 2012 7:31 am
by ganeshredcobra
Hi Giovanni,
This is the code i used
palSetPadMode(GPIOD, GPIOD_LED3, PAL_MODE_OUTPUT_PUSHPULL); /* Green. */
palSetPadMode(GPIOA, GPIOA_BUTTON,PAL_MODE_INPUT);
if (palReadPad(GPIOA, GPIOA_BUTTON))
{
palSetPad(GPIOD, GPIOD_LED3);
}
but its not working can you rectify me is there any option to use like this
if (palReadPad(GPIOA, GPIOA_BUTTON)==HIGH)
Re: checking the value on a pin
Posted: Thu Jul 26, 2012 7:42 am
by Giovanni
The code is correct but verify that the button is actually pressed while executing the palReadPad() functio.
If you are working with the default discovery board files there is no need to program the pins, the board files already do that for you. Changing the pin settings is only required if you need a setting different from the default one.
Giovanni
Re: checking the value on a pin
Posted: Thu Jul 26, 2012 7:48 am
by ganeshredcobra
But its not working...just like above said can i use HIGH or LOW option....can you post a sample code to read input from a switch and blink led...If am using an external switch what must be the input voltage given..
Re: checking the value on a pin
Posted: Thu Jul 26, 2012 7:57 am
by Giovanni
if you are reading GPIOA_BUTTON it is unlikely you will ever read your external switch, you mush specify the correct port and pin.
Giovanni
Re: checking the value on a pin
Posted: Thu Jul 26, 2012 8:06 am
by ganeshredcobra
What are the other basic tutorials that beginners can try on to understand the coding style of chibios
Re: checking the value on a pin
Posted: Thu Jul 26, 2012 8:15 am
by Giovanni
The documentation page is here:
http://www.chibios.org/dokuwiki/doku.ph ... :documentsLook for the HAL reference manual.
Then there are all the examples under ./demos and ./testhal in the source distribution.
Giovanni
Re: checking the value on a pin
Posted: Wed Aug 01, 2012 6:46 pm
by lawrenceais
I got same problem with the STM32F4-Discovery demo. I spent several hours to look for solution. And also, registered an account to ask for solution.
It also displaying error during debug:
----------------------------------
Thu Aug 02, 2012 01:36:22: The stack pointer for stack 'CSTACK' (currently 0x20000400) is outside the stack range (0x2001FC00 to 0x20020000)
----------------------------------
Finally, I found out ...... I always treat the "Reset" button as the input of "GPIOA_BUTTON".
