cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to learn the STcube/HAL-interfaces on a NUCLEO-F446RE but got stuck at a very basic level. To control a pin (LED) worked well but trying to read the button-pin (PC13) doesn't seem to work. Though an example with interrupt on that pin work. See ex.

RLind.2
Associate II

 HAL_Init();

 SystemClock_Config();// Configure the system clock to 180 MHz

 __HAL_RCC_GPIOA_CLK_ENABLE();

 GPIO_InitStruct.Pin = GPIO_PIN_13;

 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); // PC13 input (?)

 while(1)

 {

  printf("Button= %d\n", (int)HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) );// Always prints 0

  HAL_Delay(500);

 }

2 REPLIES 2
TDK
Guru

> __HAL_RCC_GPIOA_CLK_ENABLE();

> HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) );

Enable the GPIOC clock instead of GPIOA.

If you feel a post has answered your question, please click "Accept as Solution".
RLind.2
Associate II

Great thanks, now it works!!!!

Regards Ricard