Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the interrupt experiment of PIN equipment in RT-Thread

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you the PIN equipment interruption experiment on how to analyze RT-Thread. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The characteristics of general Ipaw O

The main features of the general I / O port are as follows:

1. The input and output mode can be controlled.

(1) the output modes generally include push-pull, open-leak, up-pull and down-pull. When the pin is in output mode, the connected peripheral device can be controlled by configuring the pin output level state to be high or low.

(2) input modes generally include floating, pull-up, pull-down and simulation. When the pin is in input mode, the level state of the pin can be read, that is, high level or low level.

2. Programmable control interrupt: interrupt trigger mode is configurable. Generally, there are five interrupt trigger modes as shown in the following figure:

The interrupt experiments of PIN devices are shared below.

PIN equipment interrupts the experiment

The application accesses GPIO through the PIN device management interface provided by RT-Thread, and the rt_pin_attach_irq () interface and rt_pin_irq_enable interface are used for interrupt.

According to the schematic:

When the key KEY0 is pressed, its corresponding GPIO pin should be read to a low level, so the pin mode is set to the drop-down input. Don't talk too much nonsense, just look at the code:

# include

# include

# include

# define STACK_SIZE 512

# define THREAD_PRIORITY 25

# define TIMESLICE 5

/ * interrupt callback function-

Static void hdr_callback (void * args)

{

Char * str = args

Rt_kprintf ("KEY0 pressed.% s\ n", str)

}

/ * irq thread entry function-* /

Static void irq_thread_entry (void * parameter)

{

/ * configure the KEY0 pin for pull-up input * /

Rt_pin_mode (PIN_KEY0, PIN_MODE_INPUT_PULLUP)

/ * bind the interrupt callback function with falling edge mode. The callback function parameter is the string "--By ZhengNian" * /

Rt_pin_attach_irq (PIN_KEY0, PIN_IRQ_MODE_FALLING, hdr_callback, (void*) "--By ZhengNian")

/ * enable pin break * /

Rt_pin_irq_enable (PIN_KEY0, PIN_IRQ_ENABLE)

}

/ * main function-* /

Int main (void)

{

/ * define thread handle * /

Rt_thread_t tid

/ * create dynamic pin thread: priority 25, time slice 5 system ticks, thread stack 512 bytes * /

Tid = rt_thread_create ("irq_thread"

Irq_thread_entry

RT_NULL

STACK_SIZE

THREAD_PRIORITY

TIMESLICE)

/ * start a dynamic thread if it is created successfully * /

If (tid! = RT_NULL)

{

Rt_thread_startup (tid)

}

Return 0

}

The sample code is simple: create an irq thread, configure KEY0 pins in the irq thread, bind the interrupt callback function, and finally enable KEY0 interrupts. The interrupt callback function is the function that is executed after the KEY0 triggers the interrupt.

Running result:

It can be seen that the experimental results are consistent with the expected results. It is very convenient to realize GPIO interrupt function by using PIN device framework interface.

There are many universal device driver frameworks for us to use in RTT, among which PIN device driver framework is the most basic and simplest. Is it far from mastering other device frameworks after mastering PIN device driver framework?

The above is the experiment of how to analyze the PIN device interruption of RT-Thread shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report