Example to write a value of 0xAA and then 0x55 on first 8 bits from port C.
As you notice we use the hexadecimal value 0x00FF and not the pin definitions, we can do that but the result will look like this:
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 ;
Pretty long line indeed, just remember each pin define represent a bit from an entire 16 bits value, that is why we can use the or ( | ) operator to set several pins
#include "bsp.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct; /*gpios initial structure*/
HAL_Init(); /*Init HAL library*/
__HAL_RCC_GPIOC_CLK_ENABLE(); /*Enable clock on port C*/
GPIO_InitStruct.Pin = 0x00FF; /*pins from 0 - 7 to set as output*/
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; /*output on mode push-pull*/
GPIO_InitStruct.Pull = GPIO_NOPULL; /*no pull-up niether pull-down*/
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; /*pin speed*/
/*use the previous parameters to set configuration on pins C0 - C7*/
HAL_GPIO_Init( GPIOC, &GPIO_InitStruct );
while (1)
{
/*Turn off pins from C0 to C7, second paramters of functions specify which leds will be RESET*/
HAL_GPIO_WritePin( GPIOC, 0xFF, RESET );
/*Write a value of 0xAA on port C pins from 0 to 7, second paramters of functions specify
which leds will be SET*/
HAL_GPIO_WritePin( GPIOC, 0xAA, SET );
/*Turn off pins from C0 to C7, again to write a new value*/
HAL_GPIO_WritePin( GPIOC, 0xFF, RESET );
/*Write value 0x55 on leds*/
HAL_GPIO_WritePin( GPIOC, 0x55, SET );
}
}