I spent a couple of hours trying to figure this out didn't have any luck. I am sure it is going to have to be a little c blurb.
I have some buttons I would like internal pull up / down resistor. I know there is a HAL command to do this but I don't know anything about the HAL library.
Has anyone done this on an starm?
Thanks!
Chad
edit: for clarity.
ST ARM HAL Pull up/down pin?
Moderator: Benj
-
- Posts: 198
- Joined: Sun Nov 04, 2018 7:13 pm
- Has thanked: 27 times
- Been thanked: 33 times
- Contact:
Re: ST ARM HAL Pull up/down pin?
A little update:
A friend helped me figure this out.
A friend helped me figure this out.
Code: Select all
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO pin : PC1 */
GPIO_InitStruct.Pin = GPIO_PIN_1;
//GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
//GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Pull = GPIO_PULLUP; //GPIO_NOPULL, GPIO_PULLUP or GPIO_PULLDOWN
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: ST ARM HAL Pull up/down pin?
Hi Chad,
It is possible to do the pull-up/down with C code, such as using the HAL.
It can also be done by writing directly to the registers, for example..
However, there is another issue, in that when we implement the input icons of a flowchart the HAL initialization is called,
this will turn the pulls back off again.
This is all to do with how Flowcode has historically been implemented to make things easy for the user.
We have some ideas on how to avoid this with ARM, but haven't implemented them yet to avoid upgrades breaking projects.
So if you set the pulls in C code in your project you are then best reading the input directly in C code too.
Either directly at the register...
or use the Flowcode CAL function, which will also set the pin to an input for you...
Hope that helps,
Leigh
It is possible to do the pull-up/down with C code, such as using the HAL.
It can also be done by writing directly to the registers, for example..
Code: Select all
// Port c pin 0 pull up
GPIOC->PUPDR |= 0x00000001 ;
// Port c pin 1 pull down
GPIOC->PUPDR |= 0x00000008 ;
this will turn the pulls back off again.
This is all to do with how Flowcode has historically been implemented to make things easy for the user.
We have some ideas on how to avoid this with ARM, but haven't implemented them yet to avoid upgrades breaking projects.
So if you set the pulls in C code in your project you are then best reading the input directly in C code too.
Either directly at the register...
Code: Select all
FCV_X = GPIOC->IDR & (1 << PIN_NUMBER);
Code: Select all
FCV_X = FC_CAL_Bit_In_DDR__x(GPIOC, PIN_NUMBER);
Leigh
-
- Posts: 198
- Joined: Sun Nov 04, 2018 7:13 pm
- Has thanked: 27 times
- Been thanked: 33 times
- Contact:
Re: ST ARM HAL Pull up/down pin?
Hi Leigh,
Thanks for the extra info, super helpful! I was worried about 'double' setting pins, seemed to work ok in my test but I can see how it could be a problem.
Thanks again,
Chad
Thanks for the extra info, super helpful! I was worried about 'double' setting pins, seemed to work ok in my test but I can see how it could be a problem.
Thanks again,
Chad