Embedded_GPIOSettings_Figure_00
admin

Different microcontroller GPIO settings

Share on facebook
Share on twitter
Share on linkedin

Foreword

Anyone who works with an embedded system must interact with the GPIO pins. Besides all the most basic configurations such as input, output high or low, there are many more than that supported in our microcontrollers nowadays and this blog will help you go through all of these things.

Now, let’s get started.

Some definitions

What are Tri-state (3-state), High-impedance, High-Z, Floating?

Tri-state

  • This is a term to specify that the pin can be driven to either low, high or high-z mode.
  • Don’t misuse this term with high-z or high-impedance because tri-state is not a mode. You can say “config a pin as high-z” not “config a pin as tri-state”.

Figure 01: An example of a tri-state circuit

Figure 02: 3 different states of a tri-state circuit

High-Z/High-Impedance:

  • This is one state of the tri-state. You can check the “State 3” on figure 02.
  • Whenever you configure a pin as High-Z (High-Impedance), that pin will be completely removed from the device. 

Floating:

  • This is just the result after configuring a pin as High-Z (High-Impedance). In other words, we can say “after config a pin a High-Z, that pin will be floating”.
  • The logic state of that pin is obviously unknown. It will “float” to match the residual voltage and depends on the external circuit which is connected to that pin.

Current source and Current sink

Figure 03: Current source vs current sink

Current source:

  • A device is called “current source” when it is connected with a load and supplies current that load.
  • The load can be LED, a motor…

Current sink:

  • A device is called “current sink” when it is connected with a load and the current flows from the power supply, through the load into the device.

Settings for INPUT pin

An input pin can be configured as:

  • Input pull-up
  • Input pull-down
  • Input high-z (high-impedance)

Input high-z

  • If a pin is configured as input high-z, the input default state will be indeterminate unless it is driven high or low by an external source.

Figure 04: Input high-z

Input pull-up and Input pull-down

Figure 05: Input pull-up and pull-down

  • Sometimes we might want to set the default state for the input while it is not driven by an external source, pull-up/pull-down is used in these cases.
  • With pull-up register, the default state will be HIGH and can be overridden by an external source.
  • With pull-down register, the default state will be LOW and can be overridden by an external source.
  • Let’s take a look at the case that pull-up resistor helps
Figure 06: Button with input pull-up
 
 

Settings for OUTPUT pin

An output pin can be configured as:

  • Output push-pull
  • Output open-drain (if using FET) or open-collector (if using BJT)

Output push-pull

  • There will be 2 transistors connect on the GPIO pin to VCC and GND.
  • When the output goes LOW, it is actively “pulled” to GND.
  • When the output goes HIGH, it is actively “pushed” to VCC.

Figure 07: Output push-pull

Output open-drain (or open-collector)

  • There will be 1 transistor connect on the GPIO pin to GND, the collector will be left open.
  • This is useful when we need to isolate that pin for external circuit to control (such as I2C bus in multi-master mode)

Figure 08: Output open-collector

Drive-strength

Drive-strength will determine the output impedance.
The value of drive-strength of some microcontrollers is 2mA/4mA/8mA/12mA… The default value is around 4mA.
If drive-strength is too weak, the rising and falling time of a signal are affected and you may not meet the timing specification.
If drive-strength is too strong, there are noise, overshoot, ringing can happen on the bus.

Here is the different in rising time between driver strength = 4mA and 12mA

Figure 09: Drive-strength

High-drive

Some GPIO pins are able to provide more current than typical pins and they are used for directly driving IO which requires high-current such as LED or motor. 

By using high-drive for that pin, it can avoid making another amplifying circuit, thus, reduce cost and effort. 

Slew-rate

Slew-rate is the maximum rate of change of output voltage per unit of time. There might be SLOW (default) or FAST slew-rate.

Let’s take a look at figure 10 for the slew-rate definition.

Figure 10: Slew-rate

Slow slew-rate will limit the production of high frequency. Therefore, we should use the slowest slew-rate which still satisfies the GPIO signal timing specification to minimize any possible signal integrity issues.


Update 14th, Jan 2019

Here is the simplified circuit of a physical GPIO pin on Raspberry Pi

Figure 11: Simplified circuit of Raspberry Pi physical GPIO pin

WRITTEN BY

Trung Do

Firmware engineer, blogger and a makerholic 

Related Articles

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>