1297 views|1 replies

652

Posts

1

Resources
The OP
 

[Shanghai Hangxin ACM32F070 development board + touch function evaluation board]——GPIO routine (edited with Sphinx document) [Copy link]

 

1. GPIO Example

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动图

This post is from Domestic Chip Exchange

Latest reply

The Sphinx document editor looks pretty good, and I learned a lot.   Details Published on 2022-10-20 08:00
 
 

6547

Posts

0

Resources
2
 

The Sphinx document editor looks pretty good, and I learned a lot.

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list