pio_example3_pins_and_pio_connectivity.c File Reference


Detailed Description

This example demonstrates PIO functionality.

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.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
Name
Revision
1.2
RCSfile
pio_example3_pins_and_pio_connectivity.c,v
Date
2006/05/10 12:01:41

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)


Define Documentation

#define CPU_HZ   20000000
 

Definition at line 71 of file pio_example3_pins_and_pio_connectivity.c.

#define PIN_MASK   0x000000ff
 

Definition at line 73 of file pio_example3_pins_and_pio_connectivity.c.

Referenced by main().

#define SUCCESS   0
 

Definition at line 70 of file pio_example3_pins_and_pio_connectivity.c.


Function Documentation

void delay void   ) 
 

A delay functions that delays the chip for CPU_HZ / 4.

Returns:
none

int main void   ) 
 

This is an example on using the pins and controlling the output. See comments in the source code for further information

Returns:
SUCCESS

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:


Generated on Wed May 31 07:46:56 2006 for AVR32111 Using the AVR32 PIO Controller by  doxygen 1.4.6