打印
[技术问答]

HK32F030MF4P6 SWCLK配置为EXTI问题

[复制链接]
3345|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
TI, pi, IO, ni, GPIO, gp
配置成GPIO输入是可以的,可以正常检测高低电平输入
但是配置EXTI,不能进入中断
求各位老哥帮忙看看

void Hw_Key_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    EXTI_InitTypeDef EXTI_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
   
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);  //使能GPIOB时钟
   
    //SWCLK PB5 as GPIO
    //GPIO_IOMUX_ChangePin(IOMUX_PIN11, IOMUX_PB5_SEL_PB5); //TSSOP20PIN11(PD5)PB5 IO
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
    GPIO_Init(GPIOB, &GPIO_InitStructure);
   
    /* 配置EXTI */
   
    EXTI_InitStructure.EXTI_Line = EXTI_Line5;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
   
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);
        EXTI_ClearITPendingBit(EXTI_Line5);
   
    NVIC_InitStructure.NVIC_IRQChannel = EXTI5_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
   
}

void EXTI5_IRQHandler(void)
{
   
   
    if(EXTI_GetFlagStatus(EXTI_Line5) != RESET)
    {
        //开机
        if(0 == g_key_power_flag)
        {
            Hw_Pwm_Ch3_Enable();
            Hw_Pwm_Ch4_Enable();
            g_key_power_flag = 1;
            
            Hw_Led4_On();
        }
        else
        {
            Hw_Pwm_Ch3_Disable();
            Hw_Pwm_Ch4_Disable();
            g_key_power_flag = 0;
            
            Hw_Led4_Off();
        }

        
        EXTI_ClearITPendingBit(EXTI_Line5);
    }
}

使用特权

评论回复

相关帖子

沙发
明翰的帅爸爸|  楼主 | 2021-8-24 15:39 | 只看该作者
补上一段代码
    GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
    GPIOMUX->PKG_PIN_SEL &= (uint32_t)(0xFFFFFF00);  //NRSTPA0_PIN_SEL = 0
    GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
    GPIOMUX->NRST_PA0_SEL |= (uint32_t)(0x00000007); //bit0:NRST 1 PA0  bit1-2:SWCLK 11 PB5  bit5-6:SWDIO 00 PD5

使用特权

评论回复
板凳
明翰的帅爸爸|  楼主 | 2021-8-26 16:48 | 只看该作者
已经破案了
仔细对照其他的EXTI官方例程,发现加上这个就OK了
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
HK32和STM32还是有一些细节不一样的
楼下贴出代码,希望能帮助其他人

使用特权

评论回复
地板
明翰的帅爸爸|  楼主 | 2021-8-26 16:49 | 只看该作者
void Hw_Input_Chage_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
   
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_IOMUX, ENABLE);
   
    GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
    GPIOMUX->PKG_PIN_SEL &= (uint32_t)(0xFFFFFF00);  //NRSTPA0_PIN_SEL = 0
    GPIOMUX->NRST_PIN_KEY = (uint32_t)(0x00005AE1);  //KEY
    GPIOMUX->NRST_PA0_SEL |= (uint32_t)(0x00000007); //bit0:NRST 1 PA0  bit1-2:SWCLK 11 PB5  bit5-6:SWDIO 00 PD5
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
   
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
    GPIO_InitStructure.GPIO_Schmit = GPIO_Schmit_Disable;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
   
    //NRST --> PA0
    //GPIO_IOMUX_ChangePin(IOMUX_PIN2, IOMUX_NRST_SEL_NRST);// TSSOP16 PIN2(NRST)PA0 IO  IOMUX_NRST_SEL_NRST   IOMUX_NRST_SEL_PA0
   
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void Hw_Key_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    EXTI_InitTypeDef EXTI_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
   
   
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
   
    //SWCLK PB5 as GPIO
    //GPIO_IOMUX_ChangePin(IOMUX_PIN11, IOMUX_PB5_SEL_PB5); //TSSOP20PIN11(PD5)PB5 IO
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; //引脚输入模式
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_2;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //内部上拉
    GPIO_Init(GPIOB, &GPIO_InitStructure);
   
    /* 配置EXTI */
   
    EXTI_InitStructure.EXTI_Line = EXTI_Line5;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
   
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);
        EXTI_ClearITPendingBit(EXTI_Line5);
   
    NVIC_InitStructure.NVIC_IRQChannel = EXTI5_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
   
}

//SWCLK
unsigned char Hw_Key_Get_Power_Key_Value(void)
{
    return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5);
}


unsigned char g_temp = 0;

void EXTI5_IRQHandler(void)
{
    if(EXTI_GetFlagStatus(EXTI_Line5) != RESET)
    {
        g_temp = !g_temp;
        
        if(g_temp)
            Hw_Led_Green_Enable();
        else   
            Hw_Led_Green_Disable();
        
        EXTI_ClearITPendingBit(EXTI_Line5);
    }
}

使用特权

评论回复
5
单片小菜| | 2021-8-27 11:13 | 只看该作者
这个确实已经**了,很棒的代码。不错的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

7

帖子

0

粉丝