打印
[技术问答]

HC32L110单片机GPIO中断搞不定

[复制链接]
1588|11
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wlm3000|  楼主 | 2023-9-24 19:27 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 wlm3000 于 2023-9-24 19:29 编辑

/******************************************************************************
* Copyright (C) 2016, Xiaohua Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Xiaohua Semiconductor Co.,Ltd ("XHSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with XHSC
* components. This software is licensed by XHSC to be adapted only
* for use in systems utilizing XHSC components. XHSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. XHSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* XHSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* XHSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file main.c
**
** A detailed description is available at
** @link Sample Group Some description @endlink
**
**   - 2016-02-16  1.0  XYZ First version for Device Driver Library of Module.
**
******************************************************************************/

/******************************************************************************
* Include files
******************************************************************************/
#include "gpio.h"

/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/

/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/

/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
typedef struct {
    uint8_t u8Port;
    uint8_t u8Pin;
}stc_gpio_list_t;
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/

/******************************************************************************
* Local variable definitions ('static')                                      *
******************************************************************************/
const stc_gpio_list_t gGpiolist[] =
{
    /*{ 0, 0 }, */{ 0, 1 }, { 0, 2 }, /*{ 0, 3 },*/
    { 1, 4 }, { 1, 5 },
    { 2, 3 }, { 2, 4 }, { 2, 5 }, { 2, 6 },
    { 2, 7 },
    { 3, 1 },
    { 3, 2 }, { 3, 3 }, { 3, 4 }, { 3, 5 }, { 3, 6 },


};


/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define TEST_PORT       (1)
#define TEST_PIN        (5)

#define SK_SW2_INIT()       Gpio_InitIO(3, 3, GpioDirIn)
#define SK_SW2_GET()        Gpio_GetIO(3,3)

#define NextStep()          { while (TRUE == Gpio_GetIO(3,3));\
                                delay1ms(200);\
                            }

#define SK_LED_INIT()       Gpio_InitIO(1, 5, GpioDirOut)
#define SK_LED_SET(x)       Gpio_SetIO(1,5,(x))

/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
* \brief   Gpio_IRQHandler
*          any interrput blinking a led.
*  
* \param   [in]  u8Param            port index
* \retval  void            
*/


void Gpio_IRQHandler(uint8_t u8Param)
{
    *((uint32_t *)((uint32_t)&M0P_GPIO->P3ICLR + u8Param * 0x40)) = 0;
        
    SK_LED_SET(0);
    delay1ms(500);
    SK_LED_SET(1);
    delay1ms(500);
        
}


/**
******************************************************************************
** \brief  Main function of project
**
** \return uint32_t return value, if needed
**
** This sample
**
******************************************************************************/

int32_t main(void)
{   
    //SW2 控制程序继续运行
    SK_SW2_INIT();
    NextStep();

    //GPIO初始化,配置P15为输出,外接LED
    Gpio_InitIO(TEST_PORT, TEST_PIN, GpioDirOut);
    Gpio_SetIO(TEST_PORT, TEST_PIN, TRUE);

    //初始化外部IO P33
    Gpio_InitIOExt(3, 3, GpioDirIn, TRUE, FALSE, FALSE, 0);
   
    //开启GPIO中断
    Gpio_ClearIrq(3, 3);
    //Gpio_EnableIrq(3, 3, GpioIrqRising);
          Gpio_EnableIrq(3, 3, GpioIrqFalling);
    EnableNvic(PORT3_IRQn, DDL_IRQ_LEVEL_DEFAULT, TRUE);

    while (1);
}

/******************************************************************************
* EOF (not truncated)
******************************************************************************/

这个是官方GPIO中断例程,按键触发中断后,会一直不断的进入中断,不知道怎样改,使每次触发中断后,只产生一次中断。
程序中设置的是下降沿中断,照理应该只产生一次中断

使用特权

评论回复
沙发
wlm3000|  楼主 | 2023-9-24 20:31 | 只看该作者
现在有一个正在开发的项目,使用的是HC32L110芯片,用IO口检测交流电源50HZ的过零信号去触发可控硅。GPIO中断搞不定,项目没法进行下去了。望各位高手指点!

使用特权

评论回复
板凳
Q80351951| | 2023-9-25 08:36 | 只看该作者
一直中断大概率就是中断标志没清掉

使用特权

评论回复
地板
wubangmi| | 2023-9-25 09:09 | 只看该作者

使用特权

评论回复
5
wlm3000|  楼主 | 2023-9-25 11:09 | 只看该作者
中断口是P3.3阿

使用特权

评论回复
6
xch| | 2023-9-25 12:42 | 只看该作者
void Gpio_IRQHandler(uint8_t u8Param)
{
    *((uint32_t *)((uint32_t)&M0P_GPIO->P3ICLR + u8Param * 0x40)) = 0;
        
    SK_LED_SET(0);
    delay1ms(500);
    SK_LED_SET(1);
    delay1ms(500);
        
}
===========================
看起来不像原厂的

使用特权

评论回复
7
wubangmi| | 2023-9-25 13:17 | 只看该作者

你要透过表象,理解本质。
要么你改成P0CLR,要么去掉后面的u8Param*0x40.二选一,你自己看着办

使用特权

评论回复
8
gaoyang9992006| | 2023-9-25 19:27 | 只看该作者
这个程序风格,看了头大。

使用特权

评论回复
9
wlm3000|  楼主 | 2023-9-26 13:20 | 只看该作者
改了后,功能正常了

使用特权

评论回复
10
53372370| | 2024-3-14 14:29 | 只看该作者

使用特权

评论回复
11
小夏天的大西瓜| | 2024-3-26 20:50 | 只看该作者
应该还是中断的设置问题

使用特权

评论回复
12
kmnqhaha| | 2024-4-30 17:12 | 只看该作者
中断标志没清理掉,

使用特权

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

本版积分规则

1

主题

29

帖子

0

粉丝