cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO , Button detection ( USER1) on STM32N6570-DK

emmanuel_
Associate

Post edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code

Hi  , 

I’m currently playing around with the STM32N66570-DK kit.

I’m having a simple problem with button detection. For testing, I’m just using the USER1 button  (BP1 in my code ) and LED1.

I couldn’t get the button working properly with interrupts, so in this code I just read the state of USER1 ( BP1) and turn LED1 on or off accordingly.  The USER1 button is always read as the same value, no matter whether I press it or not.  

 

in debug Mode : 

GPIOx const GPIO_TypeDef * 0x56020800
GPIO_Pin uint16_t 8192
bitstatus GPIO_PinState GPIO_PIN_RESET

 

Here are the code and screenshots. The code was generated with CubeMX.

Thanks for your help!

Once I get the button detection working, I’ll move on to using interrupts.

Emmanuel

main.h :

#define BP1_Pin GPIO_PIN_13
#define BP1_GPIO_Port GPIOC
#define LED1_Pin GPIO_PIN_1
#define LED1_GPIO_Port GPIOO

 

main.c :

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */



/* USER CODE BEGIN 3 */

// code to test the LED1

//HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);

//HAL_Delay(500);

//HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin);



// Read the button USER1



if(HAL_GPIO_ReadPin (BP1_GPIO_Port, BP1_Pin) == GPIO_PIN_RESET)

{



//Turn LED ON

HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);

}

else

{

//Turn LED OFF

HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);

}

}

/* USER CODE END 3 */

}



-----------------------------------------------------------



static void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

/* USER CODE BEGIN MX_GPIO_Init_1 */

/* USER CODE END MX_GPIO_Init_1 */



/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOO_CLK_ENABLE();



/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);



/*Configure GPIO pin : BP1_Pin */

GPIO_InitStruct.Pin = BP1_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(BP1_GPIO_Port, &GPIO_InitStruct);



/*Configure GPIO pin : LED1_Pin */

GPIO_InitStruct.Pin = LED1_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(LED1_GPIO_Port, &GPIO_InitStruct);



/* USER CODE BEGIN MX_GPIO_Init_2 */

/* USER CODE END MX_GPIO_Init_2 */

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

Hello,

You share a bed resolution images.

But to be sure, is MX_GPIO_Init() called in the main before the while loop. You shared only the while loop.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
mƎALLEm
ST Employee

Hello,

You share a bed resolution images.

But to be sure, is MX_GPIO_Init() called in the main before the while loop. You shared only the while loop.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.