【上海航芯 ACM32F070开发板+触控功能评估板】—— GPIO例程(采用Sphinx文档编辑)
[复制链接]
1. GPIO例程
按照例程编译流程即可,在main.c中选择三种例程功能
/* GPIO_INT、GPIO_PC13、LED_BLINK */
APP_GPIO_Test(LED_BLINK);
GPIO_INT是采用中断方式获取GPIO输入,并在串口输出相应的信息 代码如下:
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");
}
}
}
效果如图:
GPIO_PC13同样是采用中断方式获取GPIO输入,但是由于PC13引脚在RTC电源域(电源域同时还包括PC14、PC15),因此需要额外对RTC以及RPMU进行设置, 代码如下:
/* 注意:配置 GPIO PC13、PC14、PC15 管脚的数模、上下拉、驱动能力 使用PMU 域寄存器配置 */
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");
}
}
}
效果如图:
LED_BLINK是简单的GPIO输出0/1的例子, 代码如下:
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);
}
}
效果如图:
点击上图查看Gif动图
|