当前位置:网站首页>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;边栏推荐
- [deep learning compilation] operator compilation IR conversion
- Intermittent sampling and forwarding interference
- 【three.js】WEB3D初次体验
- 【Proteus仿真】8位端口检测8独立按键
- YuMinHong: my retreat and advance; The five best software architecture patterns that architects must understand; Redis kills 52 consecutive questions | manong weekly VIP member exclusive email weekly
- 【Spark】scala基础操作(持续更新)
- Sfdp 超级表单开发平台 V6.0.4 正式发布
- Netease cloud music beta music social app "mus" matches friends of the same frequency through music
- 降低打新的预期
- Antd - tree structure: default deployment node attribute failure - Basic promotion
猜你喜欢

Equivalence class partition method for test case design method

Good test / development programmers vs. average programmers

The SQL statement concat cannot find the result

数据中台咋就从“小甜甜”变成了“牛夫人”?

Sfdp 超级表单开发平台 V6.0.4 正式发布

利用tsne将不同句子关于相似度可视化出来

latex如何输入一个矩阵

Transaction summary on June 25, 2022

【云原生】容器场景下的内核安全

月薪没到30K的程序员必须要背的面试八股,我先啃为敬!
随机推荐
阿洛觉得自己迷茫
How to design test cases
开发者,为什么说容器技术的成熟预示着云原生时代的到来?
Sfdp 超级表单开发平台 V6.0.4 正式发布
Transaction summary on June 25, 2022
Go out and protect yourself
Online text digit recognition list summation tool
Equivalence class partition method for test case design method
If the amount exceeds 6 digits after the decimal point, only 6 digits will be reserved, and if it is less than 6 digits, it will remain the same - Basic accumulation
How to view the size of all files in a folder?
Arlo felt lost
How to switch to root in xshell
十大券商有哪些?另外,手机开户安全么?
[MRCTF2020]Ezpop-1|php序列化
元素使用 align-items center 和 overflow auto 之后,部分内容显示不全
MySQL installation steps (detailed)
Use of shortcut keys for idea tools
[recommended] how to quickly locate a bug during testing
Time flies that year
Video to image -cv2 Videocapture() usage