Read two different pins
Same config structure is use to set both pins as input,
#include "bsp.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct; /*gpios initial structure*/
HAL_Init(); /*Init HAL library*/
__HAL_RCC_GPIOB_CLK_ENABLE(); /*Enable clock on port B*/
GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5; /*pins to set as input*/
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; /*input mode*/
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 pin B4 and B5*/
HAL_GPIO_Init( GPIOB, &GPIO_InitStruct );
while(1)
{
/*Read the pin B4*/
if( HAL_GPIO_ReadPin( GPIOB, GPIO_PIN_4 ) == SET )
{
/*the pin B4 is set to high, do something*/
}
/*Read the pin B5*/
if( HAL_GPIO_ReadPin( GPIOB, GPIO_PIN_5 ) == RESET )
{
/*the pin B5 is set to low, do something*/
}
/*this is just a simple delay to avoid polling the pin to often*/
HAL_Delay( 50 );
}
}