HAL_GPIO_TogglePin()
时间: 2023-09-15 20:21:56 浏览: 252
HAL_GPIO_TogglePin() is a function in the HAL (Hardware Abstraction Layer) library of STM32 microcontrollers. It is used to toggle the state of a GPIO (General Purpose Input/Output) pin.
The function takes two arguments: the first one is the GPIO port, which can be any of the available ports on the microcontroller (GPIOA, GPIOB, GPIOC, etc.). The second argument is the pin number, which can be any pin within the selected port.
When the function is called, the state of the pin is inverted. If the pin was previously high (set to 1), it will be set to low (0), and vice versa.
Here's an example usage of HAL_GPIO_TogglePin():
```
/* Toggle the state of pin 5 in port A */
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
```
This code will toggle the state of pin 5 in port A. If the pin was previously set to high, it will now be set to low, and if it was low, it will now be high.
阅读全文