cancel
Showing results for 
Search instead for 
Did you mean: 

uint32_t Buttons_GetState (void) explanation?

Aditya Mall
Associate II
Posted on May 16, 2018 at 22:42

Hi All,

Just saw the BSP for buttons on Keil, came across this, can anyone explain how this actually works when one presses the button.

Apparently if one was supposed to press button say at pin 13 in this case, GPIOC->IDR 13th bit would be set to 1 and in this case wouldn't the if condition become false? If it is false then return value of (val) = 0 ? 

&sharpdefine USER 1

uint32_t Buttons_GetState (void)

{

   uint32_t val = 0;

   if ((GPIOC->IDR & (1ul << 13)) == 0)

   {

      /* USER button */

      val |= USER;

   }

   return (val);

}

#stm32f401re #button #bsp
2 REPLIES 2
Posted on May 16, 2018 at 23:25

one was supposed to press button say at pin 13 in this case, GPIOC->IDR 13th bit would be set to 1

This depends on whether the button is connected to ground or to positive supply.

JW

Posted on May 17, 2018 at 09:18

The button is connected to ground, actually the original issue was the inverse function it was performing as per this logic, talking about the button present on the nucleo board, which I later on realized was connected in pull up configuration.(So got this solved eventually)

Anyhow, now the pin 13 always has 3.3 v on it, and can now only used as INPUT, (is it?), Can it now be accessed as OUTPUT if I change the mode by accessing the GPIO_MODER register?

Haven't tried this but I am assuming the output voltage from the pin 13 in OUTPUT mode and PUPD (no push pull) will be the sum of output voltage from the pin and the external pull configuration ?

Also, Apart from all of this, now the user can only access pin 13 keeping in mind that reading logic from IDR has to be applied in inverse, I am not sure if the boards should be designed like this, atleast not prototyping boards.