2022-12-22 06:54 AM
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?
2022-12-22 07:34 AM
Check schematics if Wakeup button have own pull down/up. Change code SET/RESET ...
2022-12-22 07:46 AM
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.
Also, when you say change code SET/RESET, do you mean in my sample() function?
2022-12-22 08:19 AM
Check with multimeter if button 3V3 exist on PA0
2022-12-22 08:43 AM
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.
2022-12-22 08:53 AM
I try say you need check schematics if think dont work
as you can see Tamper is switched to zero and but to one.
Your sample code for tamper block code for button ...