checking the value on a pin

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

ganeshredcobra
Posts: 10
Joined: Wed Jul 25, 2012 8:40 pm

checking the value on a pin

Post 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...
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: checking the value on a pin

Post 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
ganeshredcobra
Posts: 10
Joined: Wed Jul 25, 2012 8:40 pm

Re: checking the value on a pin

Post by ganeshredcobra »

Thank you will check that :)
ganeshredcobra
Posts: 10
Joined: Wed Jul 25, 2012 8:40 pm

Re: checking the value on a pin

Post 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)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: checking the value on a pin

Post 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
ganeshredcobra
Posts: 10
Joined: Wed Jul 25, 2012 8:40 pm

Re: checking the value on a pin

Post 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..
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: checking the value on a pin

Post 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
ganeshredcobra
Posts: 10
Joined: Wed Jul 25, 2012 8:40 pm

Re: checking the value on a pin

Post by ganeshredcobra »

What are the other basic tutorials that beginners can try on to understand the coding style of chibios
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: checking the value on a pin

Post by Giovanni »

The documentation page is here:

http://www.chibios.org/dokuwiki/doku.ph ... :documents

Look for the HAL reference manual.

Then there are all the examples under ./demos and ./testhal in the source distribution.

Giovanni
lawrenceais
Posts: 4
Joined: Wed Aug 01, 2012 6:22 pm

Re: checking the value on a pin

Post 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". :oops:
Post Reply