为什么使用 GPIO?

发布于 2024-10-17 03:50:36 字数 64 浏览 3 评论 0原文

我一直在[徒劳地]寻找一些好的链接/来源来帮助理解 GPIO 以及为什么它们在嵌入式系统中使用。谁能指点我一些吗?

I have been searching around [in vain] for some good links/sources to help understand GPIOs and why they are used in embedded systems. Can anyone please point me to some ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挽清梦 2024-10-24 03:50:36

在任何有用的系统中,CPU 都必须有某种方式与外界交互 - 无论是向用户呈现的灯光或声音,还是用于与系统其他部分通信的电信号。 GPIO(通用输入/输出)引脚可让您从 CPU 外部获取程序输入或向用户提供输出。

GPIO 作为输入的一些用途:

  • 检测按钮按下情况,
  • 接收来自外部设备的中断请求

GPIO 作为输出的一些用途:

  • LED 闪烁、
  • 声音、蜂鸣器、
  • 控制外部设备的电源

双向 GPIO 或一组 GPIO 的一个很好的例子是“ bit-bang”是您的 SoC 本身不提供的协议。例如,您可以推出自己的 SPI 或 I2C 接口。

In any useful system, the CPU has to have some way to interact with the outside world - be it lights or sounds presented to the user or electrical signals used to communicate with other parts of the system. A GPIO (general purpose input/output) pin lets you either get input for your program from outside the CPU or to provide output to the user.

Some uses for GPIOs as inputs:

  • detect button presses
  • receive interrupt requests from external devices

Some uses for GPIOs as outputs:

  • blink an LED
  • sound a buzzer
  • control power for external devices

A good case for a bidirectional GPIO or a set of GPIOs can be to "bit-bang" a protocol that your SoC doesn't provide natively. You could roll your own SPI or I2C interface, for example.

慕巷 2024-10-24 03:50:36

您找不到答案的原因可能是因为如果您知道嵌入式系统是什么和做什么,或者确实了解数字电子系统,那么答案就太明显了,无法写下来!也就是说,如果您实际实现了一个可工作的嵌入式系统,您应该已经知道它们是什么。

GPIO 引脚是最小的、两种状态的数字逻辑 I/O。在大多数情况下,它们中的部分或全部也可能是中断源。这些中断可以选择上升沿、下降沿、双边沿或电平触发。

在某些目标上,GPIO 引脚可能具有可配置的输出电路,例如允许省略外部上拉,或者允许连接到需要集电极开路输出的设备,在某些情况下甚至可以过滤高频噪声和故障。

The reason you cannot find an answer is probably because if you know what an embedded system is and does, or indeed anything about digital electronic systems, then the answer is rather too obvious to write down! That is to say that if you get as far a s actually implementing a working embedded system, you should already know what they are.

GPIO pins are as a minimum, two state digital logic I/O. In most cases some or all of them may also be interrupt sources. These interrupts may have options for be rising, falling, dual edge, or level triggering.

On some targets GPIO pins may have configurable output circuitry to allow, for example, external pull-ups to be omitted, or to allow connection to devices that require open-collector outputs, and in some cases even to provide filtering of high frequency noise and glitches.

薄凉少年不暖心 2024-10-24 03:50:36

在大多数嵌入式系统中,处理器最终负责感测各种设备的状态,这些设备将外部刺激转换为数字级逻辑电压(例如,当按下按钮时,引脚将变低;否则它将变高),并且控制将逻辑电平电压直接转换为动作的设备(例如,当引脚为高电平时,灯会亮起;当为低电平时,灯会熄灭)。过去,处理器没有通用 I/O,而是必须使用共享总线与可以处理 I/O 请求并设置或报告外部电路状态的设备进行通信。尽管这种方法并非完全没有优点(一个处理器可以监视或控制共享总线上的数千个电路),但在许多实际应用中并不方便。

虽然处理器可以使用四线 SPI 总线甚至两线 I2C 总线来控制任意数量的输入和输出,但在许多情况下,处理器需要监视或控制的信号数量足够小,以至于直接在芯片本身上包含用于监视或控制某些信号的电路会更容易。尽管专用接口硬件经常具有仅输出或仅输入引脚(选择硬件接口芯片的人将知道需要监视多少信号以及需要控制多少信号),但可以使用特定系列的处理器在一些需要例如4个输入和28个输出的应用中,以及需要28个输入和4个输出的其他应用中。与其要求在输入和输出之间具有不同平衡的应用中使用不同的部件,不如只使用一个具有可根据需要配置为输入或输出的输入的部件。

In most embedded systems, a processor will be ultimately responsible for sensing the state of various devices which translate external stimuli to digital-level logic voltages (e.g. when a button is pushed, a pin will go low; otherwise it will sit high), and controlling devices which translate logic-level voltages directly into action (e.g. when a pin is high, a light will go on; when low, it will go off). It used to be that processors did not have general-purpose I/O, but would instead have to use a shared bus communicate with devices that could process I/O requests and set or report the state of the external circuits. Although this approach was not entirely without advantages (one processor could monitor or control thousands of circuits on a shared bus) it was inconvenient in many real-world applications.

While it is possible for a processor to control any number of inputs and outputs using a four-wire SPI bus or even a two-wire I2C bus, in many cases the number of signals a processor will need to monitor or control is sufficiently small that it's easier to simply include the circuitry to monitor or control some signals directly on the chip itself. Although dedicated interfacing hardware will frequently have output-only or input-only pins (the person choosing the hardware interface chips will know how many signals need to be monitored, and how many need to be controlled), a particular family of processor may be used in some applications that require e.g. 4 inputs and 28 outputs, and other applications that require 28 inputs and 4 outputs. Instead of requiring that different parts be used in applications with different balances between inputs and outputs, it's simpler to just have one part with inputs that can be configured as inputs or outputs, as needed.

清风夜微凉 2024-10-24 03:50:36

我认为你搞反了。 GPIO 是电子产品中的默认设置。它是一个引脚,一个信号,可以编程。一切都是由这些组成的。对于处理器来说,专用外设是一种特殊情况,当您知道自己想要更有限的功能时,它们是额外的。

从芯片制造商的角度来看,您通常并不确切地知道用户需要什么,因此您无法在芯片上制造准确的外设。你可以制作通用的。许多应用非常罕见,以至于特定芯片没有市场。你唯一能做的就是使用 GPIO 或自己制作特定的硬件。此外,所有(未使用或可能未使用的)引脚都值得转变为 GPIO,因为这使得该部件更加通用和可重用。通用和可重用几乎是可编程芯片的全部要点,否则你就只能制造 ASIC。

一些特别合适的应用:

  • 重置系统中的部件(芯片)
  • 开关、键盘、灯的接口(它们只有一个引脚/信号!)
  • 使用继电器或半导体开关(开-关)控制负载
    • 电磁阀、电机、加热器、阀门...
  • 从单个信号中获取中断
    • 恒温器、限位开关、液位检测器、报警装置...

顺便说一句,Parallax Propeller 除了 GPIO 引脚之外几乎什么都没有。外围设备是用软件制作的。它适用于多种用途。

I think you have it backwards. GPIO is the default in electronics. It's a pin, a signal, that can be programmed. Everything is made up of these. For a processor, dedicated peripherals are a special case, they're extras for when you know you want a more limited function.

From a chip manufacturers perspective, you often don't know exactly what the user needs so you can't make the exact peripherals on your chip. You make generic ones instead. Many applications are so rare that there's no market for a specific chip. Only thing you can do is use GPIO or make specific hardware yourself. Also, all (unused or potentially unused) pins are worth turning into GPIO because that makes the part even more generic and reusable. Generic and reusable is very nearly the whole point of programmable chips, otherwise you would just make ASICs.

Some particularly suitable applications:

  • Reset parts (chips) in a system
  • Interface to switches, keypads, lights (all they have is one pin/signal!)
  • Controlling loads with relays or semicondctor switches (on-off)
    • Solenoid, motor, heater, valve...
  • Get interrupts from single signals
    • Thermostats, limit switches, level detectors, alarm devices...

BTW, the Parallax Propeller has practically nothing but GPIO pins. Peripherals are made in software. It works very well for many uses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文