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:
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.
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.
#define PIO_PA16
Pin Controlled by PA16.
#define PIO_PA23
Pin Controlled by PA23.
#define PIOA
(PIOA ) Base Address
#define ID_PIOA
Parallel I/O Controller A (PIOA).
Workflow
- Enable the module clock to the PIOA peripheral:
- Set pin 23 direction on PIOA as output, default low level:
- 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...
void pio_clear(Pio *p_pio, const uint32_t ul_mask)
Set a low output level on all the PIOs defined in ul_mask.
void pio_set(Pio *p_pio, const uint32_t ul_mask)
Set a high output level on all the PIOs defined in ul_mask.
#define PIO_TYPE_PIO_INPUT
Workflow
- We check the value of the pin:
- Then we set the new output value based on the read pin value: