1125 views|4 replies

263

Posts

8

Resources
The OP

[Industrial-grade intelligent control MCU D133CBS] 3 - GPIO-IO interrupt [Copy link]

This post was last edited by Misaka10032 on 2024-8-18 23:17

Introduction

In this section, we will conduct an IO interrupt experiment. The specific steps are as follows: when we press the WeakUp key on the development board, the Finsh console prints a message "Key has been pressed".

The experimental phenomena are as follows:

step

1- According to the official documentation , we do not need to configure the default GPIO function in Menuconfig and can use it directly. However, if you want to use the interrupt function, you need to configure the interrupt to be enabled.

2- But if you use lunch 11 mentioned in the first two articles to start the project, you will find that the interrupt related function has been enabled.

3- Since the current development environment has already integrated RTT, we did not use the HAL function provided by JIC as described in the document.

4 - So according to the RTT official documentation of the PIN device , we can use the RTT API to operate and bind the callback.

5- According to the schematic diagram, we can initialize this wake-up key as a user button, and then bind the callback function. The PIN is PD.15.

6- The code is as follows

/*
 * Copyright (c) 2022, ArtInChip Technology Co., Ltd
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Authors: weilin.peng@artinchip.com
 */
#include <rtdevice.h>
#include <rtthread.h>
#ifdef RT_USING_ULOG
#include <ulog.h>
#endif

#define GPIO_KEY_PINc "PD.15"

/**
 * @brief  打印触发回调
 *
 * @param args
 */
void key_callback_function(void *args)
{
    rt_kprintf("%s\r\n", "Key has been presssed!");
}

void key_init(void *ags)
{

    // 设置GPIO模式
    rt_pin_mode(rt_pin_get(GPIO_KEY_PINc), PIN_MODE_INPUT_PULLUP);
    // 绑定回调函数和触发方式
    rt_pin_attach_irq(rt_pin_get(GPIO_KEY_PINc), PIN_IRQ_MODE_RISING, key_callback_function, RT_NULL);
    // 开启中断
    rt_pin_irq_enable(rt_pin_get(GPIO_KEY_PINc), PIN_IRQ_ENABLE);
}

int main(void)
{
    // 初始化
    key_init(RT_NULL);
}

Summarize

With the support of RTT driver, users do not need to be familiar with the complex HAL functions provided by various manufacturers to increase the learning cost. As long as the current chip supports RTT, we can use the same function for development, and users do not need to pay attention to the specific implementation logic of the underlying layer. This can greatly increase the user's development efficiency. The above demonstration is IO interrupt, so you can also get the IO status, configure output or input, etc.

If you don't know how to create a project, please refer to the previous link

[Industrial-grade intelligent control MCU D133CBS] 1 - Unboxing and environment setup https://bbs.eeworld.com.cn/thread-1290588-1-1.html

[Industrial-grade intelligent control MCU D133CBS] 2 - Creating a project and its precautions https://bbs.eeworld.com.cn/thread-1290861-1-1.html

This post is from Domestic Chip Exchange

Latest reply

Is there any way to compile the application I wrote separately and then put it on the board for execution? Now I can transfer files to the board, but I don't know how to compile the application separately   Details Published on 2024-12-8 14:28

5

Posts

0

Resources
2
Is this code a new file or written directly in main?
This post is from Domestic Chip Exchange

Comments

You can write directly or create a new one. You can refer to the previous two posts.  Details Published on 2024-10-11 16:22

263

Posts

8

Resources
3
haha1998 posted on 2024-10-10 16:27 Is this code in a new file or written directly in main

You can write directly or create a new one. You can refer to the previous two posts.

This post is from Domestic Chip Exchange

2

Posts

0

Resources
4

Is there any way to compile the application I wrote separately and then put it on the board for execution? Now I can transfer files to the board, but I don't know how to compile the application separately

This post is from Domestic Chip Exchange

Comments

Look at the previous posts, there are tutorials for creating new applications  Details Published on 2024-12-8 18:26

263

Posts

8

Resources
5
kaixx posted on 2024-12-8 14:28 Do you have any way to compile the application you wrote separately and then put it on the board for execution? Now I can transfer files to the board, but I don’t know how to compile the application separately...

Look at the previous posts, there are tutorials for creating new applications

This post is from Domestic Chip Exchange

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

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