cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX: Polling - Only One External Button Works

KMew
Senior III

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?

5 REPLIES 5
MM..1
Chief III

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

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?

Check with multimeter if button 3V3 exist on PA0

Hello MM,

Multimeter verified the voltage exists when the button is pressed and disappears when I release it.

Additionally, I rewrote the code, but with interrupts instead of polling modes and using GPIO_NOPULL for PA0 (Wakeup). Both buttons work without issue. So it's strictly something with the setup for the polling code.

I try say you need check schematics if think dont work

0693W00000Y6jtxQAB.pngas you can see Tamper is switched to zero and but to one.

Your sample code for tamper block code for button ...