当前位置:网站首页>HC32M0+ GPIO
HC32M0+ GPIO
2022-06-30 00:56:00 【Paper tape】
GPIO Input :
stc_gpio_cfg_t stcGpioCfg;// To configure
///< open GPIO Peripheral clock gating
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);// Start by opening GPIO The clock of .
///< Port direction configuration -> Input
stcGpioCfg.enDir = GpioDirIn;// Configure as output
///< Port drive capability configuration -> High drive capability
stcGpioCfg.enDrv = GpioDrvL;// Configure the drive capability
///< Port up and down configuration -> nothing
stcGpioCfg.enPu = GpioPuDisable;// Pull up close
stcGpioCfg.enPd = GpioPdDisable;// Pull up close
///< Port open drain output configuration -> Open drain output off
stcGpioCfg.enOD = GpioOdDisable;// Open drain output off
///< Port input / Output value register bus control mode configuration ->AHB
stcGpioCfg.enCtrlMode = GpioAHB;// The bus control mode is AHB
///< GPIO IO USER KEY initialization
Gpio_Init(STK_USER_PORT, STK_USER_PIN, &stcGpioCfg); // initialization
Input :
1. Set the clock
2. Set input and output
3. Set the driving capability
4. Pull up close
5. Open drain output off
6.AHB Pattern
7. initialization
GPIO Output
stc_gpio_cfg_t stcGpioCfg;// To configure IO Pin
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);// Set up GPIO The peripheral clock of
///< Port direction configuration -> Output ( Other parameters are the same as above ( Input ) The configuration parameters are consistent )
stcGpioCfg.enDir = GpioDirOut;// Configure as output
< Port up and down configuration -> nothing
stcGpioCfg.enPu = GpioPuDisable;
stcGpioCfg.enPd = GpioPdDisable;stc_gpio_cfg_t
typedef struct
{
en_gpio_dir_t enDir; ///< Port direction configuration // Port direction
en_gpio_drv_t enDrv; ///< Port drive capability configuration // Driving ability // Current dependent
en_gpio_pu_t enPu; ///< Port pull-up configuration
en_gpio_pd_t enPd; ///< Port drop-down configuration
en_gpio_od_t enOD; ///< Port open drain output configuration
en_gpio_ctrl_mode_t enCtrlMode; ///< Port input / Output value register bus control mode configuration // Configuration mode
}stc_gpio_cfg_t;
GPIO_IRQ
First configure as input .
stc_gpio_cfg_t stcGpioCfg;
///< open GPIO Peripheral clock gating
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);
///< Port direction configuration -> Input
stcGpioCfg.enDir = GpioDirIn;
///< Port drive capability configuration -> High drive capability
stcGpioCfg.enDrv = GpioDrvL;
///< Port up and down configuration -> nothing
stcGpioCfg.enPu = GpioPuDisable;
stcGpioCfg.enPd = GpioPdDisable;
///< Port open drain output configuration -> Open drain output off
stcGpioCfg.enOD = GpioOdDisable;
///< Port input / Output value register bus control mode configuration ->AHB
stcGpioCfg.enCtrlMode = GpioAHB;
///< GPIO IO USER KEY initialization
Gpio_Init(STK_USER_PORT, STK_USER_PIN, &stcGpioCfg); Configure falling edge / Actual interrupt number and interrupt priority
///< Open and configure USER KEY Break for falling edge
Gpio_EnableIrq(STK_USER_PORT, STK_USER_PIN, GpioIrqFalling);// Falling edge
///< Enable port PORTA System interrupt
EnableNvic(PORTA_IRQn, IrqLevel3, TRUE);// Interrupt number // Interrupt priority // How to confirm this Interrupt service function
///< PortA Interrupt service function
void PortA_IRQHandler(void)
{
if(TRUE == Gpio_GetIrqStatus(STK_USER_PORT, STK_USER_PIN))
{
///< LED Lighten up
Gpio_SetIO(STK_LED_PORT, STK_LED_PIN);
delay1ms(2000);
///< LED close
Gpio_ClrIO(STK_LED_PORT, STK_LED_PIN);
Gpio_ClearIrq(STK_USER_PORT, STK_USER_PIN);
}
} Just to summarize :
1. Make port settings
2. Enable the falling edge of the port
3. Configure interrupt vector number and interrupt priority
4. Configure interrupt service function
Insert
Interrupt response process
- Interrupt source sends interrupt request
- Determine whether the processor allows interrupts , And whether the interrupt source is shielded
- Interrupt priority queuing
- The processor pauses the current program , Protect the breakpoint address and the current state of the processor , According to the interrupt type number , Look up the interrupt vector table , Go to the corresponding interrupt service program
- Execute interrupt service procedure
- Restore the protected state , Execute interrupt return instruction , Return to the interrupted program
- When multiple interrupts occur at the same time , The processor responds to high priority interrupts first
- Low priority interrupt ISR Execution time , Can be interrupted again by high priority interrupts
- ISR Than App Code Have higher execution priority
other
typedef struct
{
boolean_t bOutputVal; ///< Default port output level
en_gpio_dir_t enDir; ///< Port direction configuration
en_gpio_drv_t enDrv; ///< Port drive capability configuration
en_gpio_pu_t enPu; ///< Port pull-up configuration
en_gpio_pd_t enPd; ///< Port drop-down configuration
en_gpio_od_t enOD; ///< Port open drain output configuration
en_gpio_ctrl_mode_t enCtrlMode; ///< Port input / Output value register bus control mode configuration
}stc_gpio_cfg_t;边栏推荐
- [daily question 1] traversal of binary tree
- 作文总写不好怎么办?猿辅导:家长要注意这几点
- Video to image -cv2 Videocapture() usage
- Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture
- ML:置信区间的简介(精密度/准确度/精确度的三者区别及其关系)、使用方法、案例应用之详细攻略
- 【Proteus仿真】8位端口检测8独立按键
- Text classification using huggingface
- 【Spark】scala基础操作(持续更新)
- 【深度学习编译】算子编译 IR 转换
- 阿于的彩虹桥
猜你喜欢

Time does not spare

初始I/O及其基本操作
![[lorawan node application] the application and power consumption of Anxin ra-08/ra-08h module in lorawan network](/img/5d/9cff7bd25841c1ca6e5ab8e2994f51.png)
[lorawan node application] the application and power consumption of Anxin ra-08/ra-08h module in lorawan network

Yunna | advantages of fixed assets system management, what are the characteristics of fixed assets management system

xshell中怎么切换到root用户

A Yu's Rainbow Bridge

2022-06-29:x = { a, b, c, d }, y = { e, f, g, h }, x、y两个小数组长度都是4。 如果有: a + e = b + f = c + g = d + h
![[qnx hypervisor 2.2 user manual]6.2.2 communication between guest and host](/img/a4/a84f916d3aa2cc59f5b686cd32797a.png)
[qnx hypervisor 2.2 user manual]6.2.2 communication between guest and host

Use of shortcut keys for idea tools

数据中台咋就从“小甜甜”变成了“牛夫人”?
随机推荐
Lower expectations
The SQL statement concat cannot find the result
2022-06-29:x = { a, b, c, d }, y = { e, f, g, h }, x、y两个小数组长度都是4。 如果有: a + e = b + f = c + g = d + h
干外包3年,真废了...
[MRCTF2020]Ezpop-1|php序列化
Good test / development programmers vs. average programmers
在线SQL转CSV工具
出门在外保护好自己
Birds in the corn field
Move DataGridView up and down
Crmeb SMS for program configuration of knowledge payment system
如何在IDEA中自定义模板、快速生成完整的代码?
岁月匆匆那年
MySQL installation steps (detailed)
ML:置信区间的简介(精密度/准确度/精确度的三者区别及其关系)、使用方法、案例应用之详细攻略
A Si's mood swings
科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
Mr. Hu Bo, CIO of weiduomei, a scientific innovator: digitalization is a bloodless revolution, and the correct answer lies in the field of business
Visual Studio 2017 无法打开包括文件: “QOpenGLFunctions_3_3_Core”: No such file or directory
Command line Basics