> For the complete documentation index, see [llms.txt](https://amriths-harijayanthan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amriths-harijayanthan.gitbook.io/notes/embedded-systems/gpio-concepts.md).

# GPIO concepts

Notes on GPIO concepts

## Introduction

* MCUs have PORTS and PINS , PORTS are a collection of PINS and each PIN has a functionality thats assigned by the manufacturer
* GPIO is used as switch , interrupts , in SPI as CS etc
* GPIO - General Purpose Input Output has the below structure&#x20;

<figure><img src="https://2053013877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKg8J6xCJHYTeKrG8eHmB%2Fuploads%2Fhc3o2IBxCQCWPTRme3dM%2FGPIO.jpg?alt=media&amp;token=d050f562-4a26-4e6b-afad-814b6e731b54" alt=""><figcaption></figcaption></figure>

## Input Confiiguration:

* PIN of an MCU can be configured as Input with pullup or pulldown resistors&#x20;
* Why pullup or pulldown ? Because if a PIN doesnt have a internal pullup or extenal pullup/down activated then it will be in floating state when nothing is connected and this will lead to wrong input read values&#x20;
* floating state can also cause leakage current (the mosfets will turn on partially and the current will leak)

<figure><img src="https://2053013877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKg8J6xCJHYTeKrG8eHmB%2Fuploads%2FWpyPs9T0jzgjjSm5gzH8%2Finput_pullup.jpg?alt=media&amp;token=e0f1d082-6d0a-4fd1-9893-128122c81b49" alt=""><figcaption></figcaption></figure>

## Output Configuration:

* Output PIN can be in open drain (pulled low when 0 but floating when 1) so it requires an external pullup resistor (use this when the current to be sourced needs to be higher than what mosfet / PIN can source)

<figure><img src="https://2053013877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKg8J6xCJHYTeKrG8eHmB%2Fuploads%2FefotiKVC9WHZQuvTRqNH%2Foutput_oD.jpg?alt=media&amp;token=139d986a-b8c1-4d8e-a0c3-78266a69f08a" alt=""><figcaption></figcaption></figure>

* Output PIN can be in Push pull configuration and this doesnt require a pullup resistor&#x20;

<figure><img src="https://2053013877-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKg8J6xCJHYTeKrG8eHmB%2Fuploads%2FLSevxgdu3cNNDeCy4RLl%2Foutput_pushpull.jpg?alt=media&amp;token=b09b2cdd-b9c5-466c-a588-cf072ce9a79d" alt=""><figcaption></figcaption></figure>
