Microchip® Advanced Software Framework

Quick Start Guide for the SAM PIO driver

This is the quick start guide for the PIO Driver, with step-by-step instructions on how to configure and use the driver for specific use cases.

The section described below can be compiled into e.g. the main application loop or any other function that will need to interface with the IO port.

PIO use cases

Basic usage of the PIO driver

This section will present a basic use case for the PIO driver. This use case will configure pin 23 on port A as output and pin 16 as an input with pullup, and then toggle the output pin's value to match that of the input pin.

Prerequisites

  • Power Management Controller driver

Initialization code

Add to the application initialization code:

pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE);
pio_set_input(PIOA, PIO_PA16, PIO_PULLUP);

Workflow

  1. Enable the module clock to the PIOA peripheral:
  2. Set pin 23 direction on PIOA as output, default low level:
    pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE);
  3. Set pin 16 direction on PIOA as input, with pullup:
    pio_set_input(PIOA, PIO_PA16, PIO_PULLUP);

Example code

Set the state of output pin 23 to match input pin 16:

if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA16))
pio_clear(PIOA, PIO_PA23);
else
pio_set(PIOA, PIO_PA23);

Workflow

  1. We check the value of the pin:
    if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA16))
  2. Then we set the new output value based on the read pin value:
    pio_clear(PIOA, PIO_PA23);
    else
    pio_set(PIOA, PIO_PA23);