Skip to main content
KMew
Senior III
December 22, 2022
Question

TouchGFX: Polling - Only One External Button Works

  • December 22, 2022
  • 5 replies
  • 1439 views

Hello,

I am using the STM32H7B3I-EVAL board with TouchGFX and I am trying to implement a feature that uses external buttons to switch between screens. I am utilizing the "Hardware button is clicked" interaction in TouchGFX and I am using a polling method to see if two different buttons are clicked.

If Wakeup Button is clicked, go to the previous screen (i.e. If I'm on Screen 2, go to Screen 1)

If the Tamper Button is clicked, go to the next screen (i.e. If I'm on Screen 2, go to Screen 3)

I followed the method in the following tutorial video:

https://www.youtube.com/watch?v=ufvJ5bcesL8

When I generated the TouchGFX portion of the code, it made this event for if the hardware button is pressed:

//Handles when a key is pressed
void Screen2ViewBase::handleKeyEvent(uint8_t key)
{
 if(1 == key)
 {
 //Screen2to1IntHW
 //When hardware button 1 clicked change screen to Screen1
 //Go to Screen1 with no screen transition
 application().gotoScreen1ScreenNoTransition();
 }
 if(0 == key)
 {
 //Screen2to3IntHW
 //When hardware button 0 clicked change screen to Screen3
 //Go to Screen3 with no screen transition
 application().gotoScreen3ScreenNoTransition();
 }
}

The polling code that I wrote to handle both buttons is provided below:

bool MyButtonController::sample(uint8_t& key){
 
	if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_SET){
		if(previousState == 0xFF){
			previousState = 0x00;
			key = 0;
			return true;
		}
		return false;
	}
	else if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == GPIO_PIN_SET){
		if(previousState == 0xFF){
			previousState = 0x00;
			key = 1;
			return true;
		}
		return false;
	}
	previousState = 0xFF;
	return false;
}

When I run this code, the Tamper button (Key = 0) works and the screen scrolls as intended. However, the Wakeup button (Key = 1) does not work. I click it and nothing happens. I have configured both the Tamper key and the Wakeup key in my GPIO initialization the same as the BSP for the STM32H7B3I-EVAL board buttons. In other words:

Tamper (Working)

 /*Configure GPIO pin : PC13 */
 GPIO_InitStruct.Pin = GPIO_PIN_13;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

Wakeup (Not Working)

 /*Configure GPIO pin : PA0 */
 GPIO_InitStruct.Pin = GPIO_PIN_0;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

I ran the debugger on my code and confirm that is enters the first if command in my sample() polling function, but not in the second if, which is my wakeup button.

Can anyone help me figure out why?

This topic has been closed for replies.

5 replies

MM..1
Super User
December 22, 2022

Check schematics if Wakeup button have own pull down/up. Change code SET/RESET ...

KMew
KMewAuthor
Senior III
December 22, 2022

Hello MM,

The BSP uses no-pull, but this is the schematic of the Wake-up button. I attempted both no-pull and pulldown though, and the result is the same.

0693W00000Y6jUyQAJ.png 

Also, when you say change code SET/RESET, do you mean in my sample() function?

MM..1
Super User
December 22, 2022

Check with multimeter if button 3V3 exist on PA0