# Maple Reference Documentation: GPIO

In addition to any special features or peripheral functions, all of the numbered Maple header pins can function as programmable digital input/output.

The current and voltage limitations have not been copied over from the stm32 datasheet; see that reference linked at the bottom. In particular a number of GPIO pins are 5v tolerant (which means that applying 5v to a pin and reading it as input or allowing it to drain to ground will not damage that pin), while some are not.

- GPIO Modes
- Function Reference
- Recommended Reading

## GPIO Modes

OUTPUT
  Basic digital output: when the pin set high the voltage is held at +3.3v (Vcc) and when set low it is pulled down to ground.
OUTPUT_OPEN_DRAIN
  In open drain mode, the pin indicates "low" by accepting current flow to ground and "high" by providing increased impedence. An example use would be to connect a pin to a bus line (which is pulled up to a positive voltage by a seperate supply through a large resistor). When the pin is high, not much current flows through to ground and the line stays at positive voltage; when the pin is low the bus "drains" to ground with a small amount of current constantly flowing through the large resistor from the external supply. In this mode no current is ever actually /sourced/ from the pin.
INPUT (or INPUT_FLOATING)
  Basic digital input. The pin voltage is sampled; when it is closer to 3.3v (Vcc) the pin status is high, and when it is closer to 0v (ground) it is low. If no external circuit is pulling the pin voltage to high or low, it will tend to randomly oscillate and be very sensitive to noise (eg a breath of air across the pin will cause the state to flip).
INPUT_PULLUP
  The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gently "pulled up" towards +3.3v. This means the state will be high unless an external device is specifically pulling the pin down to ground, in which case the "gentle" pull up will not effect the state of the input.
INPUT_PULLDOWN
  The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gently "pulled down " towards 0v. This means the state will be low unless an external device is specifically pulling the pin up to 3.3v, in which case the "gentle" pull down will not effect the state of the input.
INPUT_ANALOG
  This is a special mode for when the pin will be used for analog (not digital) reads. See the ADC page.
PWM
  This is a special mode for when the pin will be used for PWM output (a special case of digital output). See the PWM page.

## Funtion Reference

`pinMode(pin_number, MODE)`
  Usually called from within `setup()` to configure the pin. `MODE` is one of the set listed above.
`digitalRead(pin_number)`
  Returns 0 (low) or 1 (high).
`digitalWrite(pin_number, value))`
  Sets the pin to high (1) or low (0).

## Recommended Reading

- STMicro documentation for STM32F103RB microcontroller:
  - All
  - Datasheet (pdf)
  - Reference Manual (pdf)

### About this Document

A more recent version of this document may be available from the LeafLabs website. Our documentation is versioned on github; you can track changes to the master branch at this link.

This documentation is released under a Creative Commons Attribution-Share Alike 3.0 license.

Translations are welcomed; give us a ping to make sure we aren't in the process of revising or editing first.