SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
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

Initialization code

Add to the application initialization code:

pmc_enable_periph_clk(ID_PIOA);
pio_set_output(PIOA, PIO_PA23, LOW, DISABLE, ENABLE);
void pio_set_input(Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_attribute)
Configure one or more pin(s) or a PIO controller as inputs.
Definition pio.c:257
void pio_set_output(Pio *p_pio, const uint32_t ul_mask, const uint32_t ul_default_level, const uint32_t ul_multidrive_enable, const uint32_t ul_pull_up_enable)
Configure one or more pin(s) of a PIO controller as outputs, with the given default value.
Definition pio.c:310
#define PIO_PULLUP
Definition pio.h:86
#define PIO_PA16
Pin Controlled by PA16.
#define PIO_PA23
Pin Controlled by PA23.
#define PIOA
(PIOA ) Base Address
Definition sam4sd32c.h:447
#define ID_PIOA
Parallel I/O Controller A (PIOA).
Definition sam4sd32c.h:331

Workflow

  1. Enable the module clock to the PIOA peripheral:
    pmc_enable_periph_clk(ID_PIOA);
  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:

Example code

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

else
uint32_t pio_get(Pio *p_pio, const pio_type_t ul_type, const uint32_t ul_mask)
Return 1 if one or more PIOs of the given Pin instance currently have a high level; otherwise returns...
Definition pio.c:148
void pio_clear(Pio *p_pio, const uint32_t ul_mask)
Set a low output level on all the PIOs defined in ul_mask.
Definition pio.c:130
void pio_set(Pio *p_pio, const uint32_t ul_mask)
Set a high output level on all the PIOs defined in ul_mask.
Definition pio.c:117
#define PIO_TYPE_PIO_INPUT
Definition pio.h:64

Workflow

  1. We check the value of the pin:
  2. Then we set the new output value based on the read pin value: