cancel
Showing results for 
Search instead for 
Did you mean: 

Set/Reset multiple GPIO pins in one port

Ofer Ebert
Associate
Posted on June 26, 2017 at 08:53

I asked this quiestion yesterday and for some reason I do not see it in the forum ans also did not got any email about it.

I want to Set/Reset 6 GPIO pins belong to the same port using HAL what I am doing now is calling HAL_GPIO_WritePin 6 times which take too much time how can I do it it one command.since all pins are of the same port.

#gpio
2 REPLIES 2
Posted on June 26, 2017 at 09:10

You can write GPIOx_BSRR with a 32-bit value in a single step - the lower 16-bit for those bits which have to be set and the upper 16-bit for those which have to be cleared. This is a perfectly atomic operation. See GPIO chapter in RM. I don't know if this has some name in Cube's.

JW

misagh
Associate III
Posted on June 26, 2017 at 09:26

Hi,

You can set all pins you want at one function call and reset another pins at one function call like this:

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_RESET);

Bests,

Misagh