PULL-UP Input Topic is solved
Moderator: RoccoMarco
PULL-UP Input
Hi to all,
I configured the GPIOB0 pin as input, the code is the following:
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT(0)|PIN_PUPDR_PULLUP(0));
And in an another board I configured GPIOA7 as output.
palSetPadMode(GPIOA, 7, PAL_STM32_MODE_OUTPUT);
The pin A7 have to generate a square wave, and everythings works fine, but when I connect A7 to B0 the sqare wave is not able to go to 0V again.
The wave no longer oscillates between 3 and 0 but it oscillates between 1 and 3. Why? Where I am wrong?
Thanks to all!
I configured the GPIOB0 pin as input, the code is the following:
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT(0)|PIN_PUPDR_PULLUP(0));
And in an another board I configured GPIOA7 as output.
palSetPadMode(GPIOA, 7, PAL_STM32_MODE_OUTPUT);
The pin A7 have to generate a square wave, and everythings works fine, but when I connect A7 to B0 the sqare wave is not able to go to 0V again.
The wave no longer oscillates between 3 and 0 but it oscillates between 1 and 3. Why? Where I am wrong?
Thanks to all!
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Has thanked: 83 times
- Been thanked: 67 times
Re: PULL-UP Input
HI,
as Giovanni says bit masks are wrong. If I understand well you have two different boards. In this case remember to refer them to the same ground.
as Giovanni says bit masks are wrong. If I understand well you have two different boards. In this case remember to refer them to the same ground.
Re: PULL-UP Input
Hi Giovanni, hi RoccoMarco,
thanks for your reply. I have already connected the grounds.
I agree with you Giovanni that those (0) makes no sense, but if I remove those (0) :
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
The compiler gives me an error.
[spoil]08:52:58 **** Incremental Build of configuration Default for project CAN_Back_Bone ****
make -j4 all
Compiling extlib.c
In file included from ../../chibios161/os/hal/include/pal.h:113:0,
from ../../chibios161/os/hal/include/hal.h:47,
from ./userlib/include/extlib.h:3,
from ./userlib/src/extlib.c:1:
./userlib/src/extlib.c: In function 'gpioconfig':
./userlib/src/extlib.c:101:27: error: 'PIN_MODE_INPUT' undeclared (first use in this function)
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
./userlib/src/extlib.c:101:27: note: each undeclared identifier is reported only once for each function it appears in
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
./userlib/src/extlib.c:101:44: error: 'PIN_PUPDR_PULLUP' undeclared (first use in this function)
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
make: *** [build/obj/extlib.o] Error 1
08:52:59 Build Finished (took 1s.973ms)[/spoil]
I do not understand how to make the PIN 0 as input pin and connect it with the weak pull-up resistor built-in in the MCU.
P.S. the B0 pin is also used by the EXTI peripheral, but i don't think that is a limitation.
thanks for your reply. I have already connected the grounds.
I agree with you Giovanni that those (0) makes no sense, but if I remove those (0) :
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
The compiler gives me an error.
[spoil]08:52:58 **** Incremental Build of configuration Default for project CAN_Back_Bone ****
make -j4 all
Compiling extlib.c
In file included from ../../chibios161/os/hal/include/pal.h:113:0,
from ../../chibios161/os/hal/include/hal.h:47,
from ./userlib/include/extlib.h:3,
from ./userlib/src/extlib.c:1:
./userlib/src/extlib.c: In function 'gpioconfig':
./userlib/src/extlib.c:101:27: error: 'PIN_MODE_INPUT' undeclared (first use in this function)
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
./userlib/src/extlib.c:101:27: note: each undeclared identifier is reported only once for each function it appears in
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
./userlib/src/extlib.c:101:44: error: 'PIN_PUPDR_PULLUP' undeclared (first use in this function)
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
../../chibios161/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h:528:47: note: in definition of macro 'pal_lld_setgroupmode'
_pal_lld_setgroupmode(port, mask << offset, mode)
^
../../chibios161/os/hal/include/pal.h:527:3: note: in expansion of macro 'palSetGroupMode'
palSetGroupMode(port, PAL_PORT_BIT(pad), 0U, mode)
^
./userlib/src/extlib.c:101:3: note: in expansion of macro 'palSetPadMode'
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT | PIN_PUPDR_PULLUP);
^
make: *** [build/obj/extlib.o] Error 1
08:52:59 Build Finished (took 1s.973ms)[/spoil]
I do not understand how to make the PIN 0 as input pin and connect it with the weak pull-up resistor built-in in the MCU.
P.S. the B0 pin is also used by the EXTI peripheral, but i don't think that is a limitation.
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Has thanked: 83 times
- Been thanked: 67 times
Re: PULL-UP Input
Indeed you should write,
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT_PULLUP);
Take a look to hal reference manual.
palSetPadMode(GPIOB, 0, PIN_MODE_INPUT_PULLUP);
Take a look to hal reference manual.
Re: PULL-UP Input
Hi Marco,
The line code you wrote is not accepted by the compiler. it says it is not defined.
I searched the string "PIN_MODE_INPUT_PULLUP" in my chibistudio project and I have been not able to find its declaration.
I am reading the RM, and I see that the pull-up resistor on B0 is activated simply by setting the register GPIOB_PUPDR=0x00000001, but I would like to use the hal and the macros.
Thank you for your help!
The line code you wrote is not accepted by the compiler. it says it is not defined.
I searched the string "PIN_MODE_INPUT_PULLUP" in my chibistudio project and I have been not able to find its declaration.
I am reading the RM, and I see that the pull-up resistor on B0 is activated simply by setting the register GPIOB_PUPDR=0x00000001, but I would like to use the hal and the macros.
Thank you for your help!
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Has thanked: 83 times
- Been thanked: 67 times
- RoccoMarco
- Posts: 655
- Joined: Wed Apr 24, 2013 4:11 pm
- Has thanked: 83 times
- Been thanked: 67 times
Re: PULL-UP Input
C:\ChibiStudio\chibios161\os\hal\include\hal.h
BTW in the same directory take a look to pal.h
If you cannot find PAL_MODE_INPUT_PULLUP I am afraid you have screwed up something.
Code: Select all
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @brief ChibiOS/HAL identification macro.
*/
#define _CHIBIOS_HAL_
/**
* @brief Stable release flag.
*/
#define CH_HAL_STABLE 1
/**
* @name ChibiOS/HAL version identification
* @{
*/
/**
* @brief HAL version string.
*/
#define HAL_VERSION "4.0.6"
/**
* @brief HAL version major number.
*/
#define CH_HAL_MAJOR 4
/**
* @brief HAL version minor number.
*/
#define CH_HAL_MINOR 0
/**
* @brief HAL version patch number.
*/
#define CH_HAL_PATCH 6
/** @} */
/**
* @name Return codes
* @{
*/
#define HAL_SUCCESS false
#define HAL_FAILED true
/** @} */BTW in the same directory take a look to pal.h
Code: Select all
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @name Pads mode constants
* @{
*/
/**
* @brief After reset state.
* @details The state itself is not specified and is architecture dependent,
* it is guaranteed to be equal to the after-reset state. It is
* usually an input state.
*/
#define PAL_MODE_RESET 0U
/**
* @brief Safe state for <b>unconnected</b> pads.
* @details The state itself is not specified and is architecture dependent,
* it may be mapped on @p PAL_MODE_INPUT_PULLUP,
* @p PAL_MODE_INPUT_PULLDOWN or @p PAL_MODE_OUTPUT_PUSHPULL for
* example.
*/
#define PAL_MODE_UNCONNECTED 1U
/**
* @brief Regular input high-Z pad.
*/
#define PAL_MODE_INPUT 2U
/**
* @brief Input pad with weak pull up resistor.
*/
#define PAL_MODE_INPUT_PULLUP 3U
/**
* @brief Input pad with weak pull down resistor.
*/
#define PAL_MODE_INPUT_PULLDOWN 4U
/**
* @brief Analog input mode.
*/
#define PAL_MODE_INPUT_ANALOG 5U
/**
* @brief Push-pull output pad.
*/
#define PAL_MODE_OUTPUT_PUSHPULL 6U
/**
* @brief Open-drain output pad.
*/
#define PAL_MODE_OUTPUT_OPENDRAIN 7U
/** @} */If you cannot find PAL_MODE_INPUT_PULLUP I am afraid you have screwed up something.