This examples demonstrates how to set pins under control of the PIO Controller or let connected modules utilize the I/O pins. See the documentation for settings and how to deploy this example on target.
Definition in file pio_example3_pins_and_pio_connectivity.c.
#include "pio.h"
Include dependency graph for pio_example3_pins_and_pio_connectivity.c:

Go to the source code of this file.
Defines | |
| #define | CPU_HZ 20000000 |
| #define | PIN_MASK 0x000000ff |
| #define | SUCCESS 0 |
Functions | |
| void | delay (void) |
| int | main (void) |
|
|
Definition at line 71 of file pio_example3_pins_and_pio_connectivity.c. |
|
|
Definition at line 73 of file pio_example3_pins_and_pio_connectivity.c. Referenced by main(). |
|
|
Definition at line 70 of file pio_example3_pins_and_pio_connectivity.c. |
|
|
A delay functions that delays the chip for CPU_HZ / 4.
|
|
|
This is an example on using the pins and controlling the output. See comments in the source code for further information
Definition at line 85 of file pio_example3_pins_and_pio_connectivity.c. References delay(), PIN_MASK, pio_enable_module(), and SUCCESS. 00086 { 00087 /* 00088 For this example to work, connect J15 to J1 00089 */ 00090 00091 volatile avr32_pio_t *piob = &AVR32_PIOB; 00092 00093 /* 00094 The gcc header files contains pinout information. Each pin is numbered with a positive integer. 00095 This number is between 0 and the number of pins of your chosen device. If you divide the it by 32, 00096 you will get the port number. I.e. 34 / 32 is 1. That means that pin 34 is part of port B. 00097 Then, if the modulo 32 is calculted, you will get the pin number on the port. I.e. 34 % 32 is 2. 00098 Thus, the pin description 34 gives PORTB, pin 2. 00099 00100 In addition each pin is connected to the PIO Controller. The actual pin can be driven by the PIO 00101 Controller itself or by one of the two possible connected modules. 00102 00103 Each I/O pin of a module is described in the header files in the following way; 00104 AVR32_{module}{instance}_{pin}_{mapping_instance}_PIN, i.e AVR32_USART1_RXD_0_PIN 00105 00106 A specific I/O can be connected to one of the two possible connection, as is described in the header 00107 files as: 00108 AVR32_{module}{instance}_{pin}_{mapping_instance}_FUNCTION, i.e AVR32_USART1_RXD_0_FUNCTION 00109 00110 The FUNCTION definition of a pin can either be 0 or 1, which indicates if it is connected to module A or B of the 00111 PIO Controller, respectively. 00112 00113 This information can be used to enble the set of pins you need for I/O for module communication. 00114 00115 Note: The mapping instance is used whenever a specific output is routed to several pins. When a single I/O from 00116 a module is routed to only one pin, 0 is always used. 00117 00118 */ 00119 00120 /* bit 0..7 on port B is set as output */ 00121 piob->per = PIN_MASK; /* Set pio enable for 16 LSBs of PORTB */ 00122 piob->oer = PIN_MASK; /* Make them output ports */ 00123 piob->idr = PIN_MASK; /* Disable interrupts on these pins */ 00124 piob->puer = PIN_MASK; /* Enable pull-ups */ 00125 piob->ower = PIN_MASK; /* Enable writing for the ODSR I/O line */ 00126 piob->codr = PIN_MASK; /* Clear output */ 00127 00128 /* A list of pins to set under a module's control is generated */ 00129 avr32_piomap_t test_piomap = { 00130 {32, 0}, /* port B, pin 0 */ 00131 {33, 0} /* port B, pin 1 */ 00132 }; 00133 00134 /* These pins are set under the module's control */ 00135 pio_enable_module(test_piomap,2); 00136 00137 /* We will toggle the leds */ 00138 while(1){ 00139 piob->odsr = ~(piob->odsr & PIN_MASK); 00140 delay(); 00141 /* 00142 Note: You will see that only LED[2..7] toggles, as LED[0..1] is put under module A's control. 00143 These data from the PIO controller is not pushed out the pin. 00144 */ 00145 } 00146 00147 return SUCCESS; 00148 }
Here is the call graph for this function: ![]() |
1.4.6