Gpio Ibus

Posted on
  1. Gpio Buffer

Ultimately, I want to configure various GPIO pins to use them in 'Alternate Function' mode for read/write access to SRAM. Of all the GPIO registers available, I do not understand two: GPIOPUPDR and GPIOOTYPE which are respectively the 'pull-up/pull-down register' and the 'output type register'. For GPIOPUPDR I have three choices. A general-purpose input/output (GPIO) is an uncommitted digital signal pin on an integrated circuit or electronic circuit board whose behavior—including whether it acts as input or output—is controllable by the user at run time. GPIOs have no predefined purpose and are unused by default.

Active4 months ago
$begingroup$

I am reading the datasheet of an ARM Cortex chip, specifically the GPIO chapter. Ultimately, I want to configure various GPIO pins to use them in 'Alternate Function' mode for read/write access to SRAM.

Of all the GPIO registers available, I do not understand two: GPIO_PUPDR and GPIO_OTYPE which are respectively the 'pull-up/pull-down register' and the 'output type register'.

For GPIO_PUPDR I have three choices:

  • No pull-up or pull-down
  • Pull-up
  • Pull down

For GPIO_0TYPE I have two choices:

  • Output push-pull
  • Output open-drain

What is the difference between all the different configurations, and which would be the most appropriate for SRAM communication?

The documentation for the board I am working on is available here (see page 24 for the SRAM schematics). The reference manual for the ARM Chip is available here (see pages 145 and 146 for the GPIO registers).

stevenvh
135k16 gold badges427 silver badges637 bronze badges
RandomblueRandomblue
4,56023 gold badges82 silver badges156 bronze badges
$endgroup$Ibus

3 Answers

$begingroup$

This answer is general to processors and peripherals, and has an SRAM specific comment at the end, which is probably pertinent to your specific RAM and CPU.

Output pins can be driven in three different modes:

  • open drain - a transistor connects to low and nothing else
  • open drain, with pull-up - a transistor connects to low, and a resistor connects to high
  • push-pull - a transistor connects to high, and a transistor connects to low (only one is operated at a time)

Input pins can be a gate input with a:

  • pull-up - a resistor connected to high
  • pull-down - a resistor connected to low
  • pull-up and pull-down - both a resistor connected to high and a resistor connected to low (only useful in rare cases).

There is also a Schmitt triggered input mode where the input pin is pulled with a weak pull-up to an initial state. When left alone it persists in its state, but may be pulled to a new state with minimal effort.

Open drain is useful when multiple gates or pins are connected together with an (external or internal) pull-up. If all the pin are high, they are all open circuits and the pull-up drives the pins high. If any pin is low they all go low as they tied together. This configuration effectively forms an AND gate.

When driving an SRAM you probably want to drive either the data lines or the address lines high or low as solidly and rapidly as possible so that active up and down drive is needed, so push-pull is indicated. In some cases with multiple RAMs you may want to do something clever and combine lines, where another mode may be more suitable.

With SRAM with data inputs from the SRAM if the RAM IC is always asserting data then a pin with no pull-up is probably OK as the RAM always sets the level and this minimises load. If the RAM data lines are sometimes open circuit or tristate you will need the input pins to be able to set their own valid state. In very high speed communications you may want to use a pull-up and and a a pull-down so the parallel effective resistance is the terminating resistance, and the bus idle voltage is set by the two resistors, but this is somewhat specialist.

Randomblue
4,56023 gold badges82 silver badges156 bronze badges
Russell McMahonRussell McMahon
122k9 gold badges168 silver badges308 bronze badges
$endgroup$$begingroup$

I found this answer from STM32 Understanding GPIO Settings

  • GPIO_PuPd (Pull-up / Pull-down)

In digital circuits, is is important that signal lines are never allowed to 'float'. That is, they need to always be in a high state or a low state. When floating, the state is undetermined, and causes a few different types of problems.

The way to correct this is to add a resistor from the signal line either to Vcc or Gnd. That way, if the line is not being actively driven high or low, the resistor will cause the potential to drift to a known level.

The ARM (and other microcontrollers) have built-in circuitry to do this. That way, you don't need to add another part to your circuit. If you choose 'GPIO_PuPd_UP', for example, it is equivelent to adding a resistor between the signal line and Vcc.

  • GPIO_OType (Output Type):

Push-Pull: This is the output type that most people think of as 'standard'. When the output goes low, it is actively 'pulled' to ground. Conversely, when the output is set to high, it is actively 'pushed' toward Vcc. Simplified, it looks like this:

An Open-Drain output, on the other hand, is only active in one direction. It can pull the pin towards ground, but it cannot drive it high. Imagine the previous image, but without the upper MOSFET. When it is not pulling to ground, the (lower-side) MOSFET is simply non-conductive, which causes the output to float.

For this type of output, there needs to be a pull-up resistor added to the circuit, which will cause the line to go high when not driven low. You can do this with an external part, or by setting the GPIO_PuPd value to GPIO_PuPd_UP.

The name comes from the fact that the MOSFET's drain isn't internally connected to anything. This type of output is also called 'open-collector' when using a BJT instead of a MOSFET.

  • GPIO_Speed

Basically, this controls the slew rate (the rise time and fall time) of the output signal. The faster the slew rate, the more noise is radiated from the circuit. It is good practice to keep the slew rate slow, and only increase it if you have a specific reason.

Community
AbhishekAbhishek
$endgroup$$begingroup$

One more little tid-bit: for microcontrollers that don't have an explicit 'open drain' mode, such as AVR and Arduino ATmega328-based boards such as the Uno, this 'open drain' mode can be simulated by writing a wrapper function which simply sets a pin to 'Output LOW' when you send it a 0 and which configures the pin as an 'Input LOW' (high impedance mode, internal pullup-resistor NOT on) when you send it a 1. In this way you get the same effect. These modern 32-bit ARM-core microcontrollers just have a lot more options is all.

Also, p146 of the STM32 Reference Manual linked to above states the following [my additions are in square brackets]:

– Open drain mode: A “0” in the Output register activates the N-MOS [thereby actively driving LOW by connecting the pin to GND] whereas a “1” in the Output register leaves the port in Hi-Z (the P-MOS is never activated) [high impedance mode--same as a floating input with no pull-up or pull-down resistors]

– Push-pull mode: A “0” in the Output register activates the N-MOS [actively drives LOW by connecting the pin to GND] whereas a “1” in the Output register activates the P-MOS [actively drives HIGH by connecting the pin to VCC]

In Arduino code that 'wrapper function' could be implemented like this:

Or simplified:

Note that to turn on the internal pullup resistor on an Arduino you can do:

OR (same thing):

  • (Really good and concise article by Phillip Johnston): https://embeddedartistry.com/blog/2018/6/4/demystifying-microcontroller-gpio-settings
Gabriel StaplesGabriel Staples
3941 gold badge3 silver badges16 bronze badges
Gpio buttons driver windows 10$endgroup$

Not the answer you're looking for? Browse other questions tagged microcontrollergpio or ask your own question.

A general-purpose input/output (GPIO) is an uncommitted digital signal pin on an integrated circuit or electronic circuit board whose behavior—including whether it acts as input or output—is controllable by the user at run time.

GPIOs have no predefined purpose and are unused by default.[1][2] If used, the purpose and behavior of a GPIO is defined and implemented by the designer of higher assembly-level circuitry: the circuit board designer in the case of integrated circuit GPIOs, or system integrator in the case of board-level GPIOs.

Integrated circuit GPIOs[edit]

Integrated circuit (IC) GPIOs are implemented in a variety of ways. Some ICs provide GPIOs as a primary function whereas others include GPIOs as a convenient 'accessory' to some other primary function. Examples of the former include the Intel 8255, which interfaces 24 GPIOs to a parallel bus, and various GPIO 'expander' ICs, which interface GPIOs to serial buses such as I²C and SMBus. An example of the latter is the Realtek ALC260 IC, which provides eight GPIOs in addition to its primary function of audio codec.

Microcontroller ICs typically include GPIOs. Depending on the application, a microcontroller's GPIOs may comprise its primary interface to external circuitry or they may be just one type of I/O used among several, such as analog I/O, counter/timer, and serial communication.

Gpio Buffer

In some ICs, particularly microcontrollers, a GPIO pin may be capable of alternate functions. Often in such cases, it is necessary to configure the pin to operate as a GPIO (vs. its alternate functions) in addition to configuring the GPIO's behavior. Some microcontroller devices (e.g., Microchip dsPIC33 family) incorporate internal signal routing circuitry that allows GPIOs to be programmatically mapped to device pins. FPGAs extend this capability by allowing GPIO pin mapping, instantiation and architecture to be programmatically controlled.

  • Parallel bus interface to 24 GPIOs (Intel 8255)

  • A 'versatile interface adapter', which combines 20 GPIOs with other general-purpose interfaces (MOS Technology 6522) Metin2 yang hack dowland mp3.

  • A microcontroller with 29 remappable GPIOs (Microchip Technology PIC24FJ256)

Board-level GPIOs[edit]

Many circuit boards expose board-level GPIOs to external circuitry through integrated electrical connectors. Typically, each such GPIO is accessible via a dedicated connector pin.

Like IC-based GPIOs, some boards merely include GPIOs as a convenient, auxiliary resource that augments the board's primary function, whereas in other boards the GPIOs are the central, primary function of the board. Some boards, which typically are classified as multi-function I/O boards, are a combination of both; such boards provide GPIOs along with other types of general-purpose I/O. GPIOs are also found on embedded controller boards such as Arduino, BeagleBone and Raspberry Pi.[3]

Board-level GPIOs are often endowed with capabilities which typically are not found in IC-based GPIOs. For example, schmitt-trigger inputs, high-current output drivers, optical isolators, or combinations of these may be used to buffer and condition the GPIO signals and to protect board circuitry. Also, higher-level functions are sometimes implemented, such as input debounce, input signal edge detection, and pulse-width modulation (PWM) output.

  • Network router with three GPIOs (Banana Pi R1)

  • GPIO interface for Hewlett-Packard Series 80 computers (HP 82940A)

  • Ethernet interface to 48 GPIOs (Sensoray 2410)

Usage[edit]

GPIOs are used in a diverse variety of applications, limited only by the electrical and timing specifications of the GPIO interface and the ability of software to interact with GPIOs in a sufficiently timely manner.

GPIOs typically employ standard logic levels and cannot supply significant current to output loads. When followed by an appropriate high-current output buffer (or mechanical or solid-state relay), a GPIO may be used to control high-power devices such as lights, solenoids, heaters, and motors (e.g., fans and blowers). Similarly, an input buffer, relay or opto-isolator is often used to translate an otherwise incompatible signal (e.g., high voltage) to the logic levels required by a GPIO.

Integrated circuit GPIOs are commonly used to control or monitor other circuitry (including other ICs) on a board. Examples of this include enabling and disabling the operation of (or power to) other circuitry, reading the states of on-board switches and configuration shunts, and driving LED status indicators. In the latter case, a GPIO can, in many cases, supply enough output current to directly power an LED without using an intermediate buffer.

Multiple GPIOs are sometimes used together as a bit-banged communication interface. For example, two GPIOs may be used to implement a serial communication bus such as I²C, and four GPIOs can be used to implement an SPI bus; these are typically used to facilitate serial communication with ICs and other devices which have compatible serial interfaces, such as sensors (e.g., temperature sensors, pressure sensors, accelerometers) and motor controllers. Taken to the extreme, this technique may be used to implement an entire parallel bus, thus allowing communication with bus-oriented ICs or circuit boards.

Although GPIOs are fundamentally digital in nature, they are often used to control linear processes. For example, a GPIO may be used to control motor speed, light intensity, or temperature. Typically, this is accomplished via PWM, in which the duty cycle of the GPIO output signal determines the effective magnitude of the process control signal. For example, when controlling light intensity, the light may be dimmed by reducing the GPIO duty cycle. Some linear processes require a linear control voltage; in such cases it may be feasible to connect a GPIO -- which is operated as a PWM output -- to an RC filter to create a simple and inexpensive digital-to-analog converter.

Implementation[edit]

GPIO interfaces vary widely. In some cases, they are simple—a group of pins that can switch as a group to either input or output. In others, each pin can be set up to accept or source different logic voltages, with configurable drive strengths and pull ups/downs. Input and output voltages are typically—though not always—limited to the supply voltage of the device with the GPIOs, and may be damaged by greater voltages.

A GPIO pin's state may be exposed to the software developer through one of a number of different interfaces, such as a memory mapped peripheral, or through dedicated IO port instructions. Some GPIOs have 5 V tolerant inputs: even when the device has a low supply voltage (such as 2 V), the device can accept 5 V without damage.

A GPIO port is a group of GPIO pins (typically 8 GPIO pins) arranged in a group and controlled as a group.[4]

GPIO capabilities may include:[2]

  • GPIO pins can be configured to be input or output[4]
  • GPIO pins can be enabled/disabled
  • Input values are readable (typically high or low)
  • Output values are writable/readable
  • Input values can often be used as IRQs (typically for wakeup events)

See also[edit]

References[edit]

  1. ^White, Jon, ed. (2016). Raspberry Pi - The Complete Manual (7 ed.). Imagine Publishing. p. 36. ISBN978-1785463709.
  2. ^ ab'General Purpose Input/Output'. Oracle® Java ME Embedded Developer's Guide (8 ed.). Oracle Corporation. 2014.
  3. ^'GPIO - Raspberry Pi Documentation'. Raspberry Pi Foundation. Retrieved 3 November 2016.
  4. ^ abBalachandran, Sasang (2009). General Purpose Input/Output (GPIO)(PDF). Michigan State University College of Engineering.

External links[edit]

Retrieved from 'https://en.wikipedia.org/w/index.php?title=General-purpose_input/output&oldid=903282908'