[Shanghai Hangxin ACM32F070 development board + touch function evaluation board]——GPIO routine (edited with Sphinx document)
[Copy link]
Just follow the routine compilation process and select three routine functions in main.c
/* GPIO_INT、GPIO_PC13、LED_BLINK */
APP_GPIO_Test(LED_BLINK);
GPIO_INT uses interrupt mode to obtain GPIO input and outputs the corresponding information on the serial port. The code is as follows:
case GPIO_INT:
{
printfS("This is GPIO interrupt TEST \r\n");
GPIOA_Handle.Pin = GPIO_PIN_0;
GPIOA_Handle.Mode = GPIO_MODE_IT_FALLING;
GPIOA_Handle.Pull = GPIO_PULLUP;
GPIOA_Handle.Alternate = GPIO_FUNCTION_0;
HAL_GPIO_Init(GPIOA, &GPIOA_Handle);
/* Clear Pending Interrupt */
NVIC_ClearPendingIRQ(GPIOAB_IRQn);
/* Enable External Interrupt */
NVIC_EnableIRQ(GPIOAB_IRQn);
while (1)
{
if (gu32_GPIOIRQ_Flag)
{
gu32_GPIOIRQ_Flag = false;
printfS("Get interrupt flag!!! \r\n");
}
}
}
The effect is as shown below:
GPIO_PC13 also uses interrupts to obtain GPIO input, but because the PC13 pin is in the RTC power domain (the power domain also includes PC14 and PC15), it is necessary to set up the RTC and RPMU additionally. The code is as follows:
/* Note: Use the PMU domain registers to configure the digital-analog, pull-up/pull-down, and drive capabilities of the GPIO PC13, PC14, and PC15 pins*/
case GPIO_PC13:
{
printfS("This is GPIO PC13 interrupt TEST \r\n");
GPIOC_Handle.Pin = GPIO_PIN_13;
GPIOC_Handle.Mode = GPIO_MODE_IT_FALLING;
GPIOC_Handle.Alternate = GPIO_FUNCTION_0;
HAL_GPIO_Init(GPIOC, &GPIOC_Handle);
/* RTC access enable */
System_Enable_Disable_RTC_Domain_Access(FUNC_ENABLE);
__HAL_RTC_PC13_SEL(0); // GPIO function
__HAL_RTC_PC13_PULL_UP_ENABLE();
__HAL_RTC_PC13_DIGIT();
/* Clear Pending Interrupt */
NVIC_ClearPendingIRQ(GPIOCD_IRQn);
/* Enable External Interrupt */
NVIC_EnableIRQ(GPIOCD_IRQn);
while (1)
{
if (gu32_GPIOIRQ_Flag)
{
gu32_GPIOIRQ_Flag = false;
printfS("Get PC13 interrupt flag!!! \r\n");
}
}
}
The effect is as shown below:
LED_BLINK is a simple example of GPIO output 0/1. The code is as follows:
case LED_BLINK: // use PA1 to drive LED
{
printfS("This is LED Blinking TEST \r\n");
GPIOD_Handle.Pin = GPIO_PIN_3;
GPIOD_Handle.Mode = GPIO_MODE_OUTPUT_PP;
GPIOD_Handle.Pull = GPIO_PULLUP;
GPIOD_Handle.Alternate = GPIO_FUNCTION_0;
HAL_GPIO_Init(GPIOD, &GPIOD_Handle);
GPIOD_Handle.Pin = GPIO_PIN_2;
GPIOD_Handle.Mode = GPIO_MODE_OUTPUT_PP;
GPIOD_Handle.Pull = GPIO_PULLUP;
GPIOD_Handle.Alternate = GPIO_FUNCTION_0;
HAL_GPIO_Init(GPIOD, &GPIOD_Handle);
while (1)
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);
System_Delay_MS(500);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_CLEAR);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_CLEAR);
System_Delay_MS(500);
}
}
The effect is as shown below:
点击上图查看Gif动图
|