# AVR32 AP7 - SPI Driver Documentation

## Introduction

This is the documentation for the data structures, functions, variables, defines, enums, and typedefs in the software for application note AVR32105. It also gives an example of the usage of the SPI driver for both master and slave mode.

## Main Files

- spi_at32ap7000.c: SPI driver source
- spi_at32ap7000.h: SPI driver header
- spi_example.c: SPI example

## Compilation Info

This software was written for the GNU GCC for AVR32 and IAR Systems compiler for AVR32. Other compilers may or may not work.

## Device Info

All AVR32 devices with a SPI module can be used. This example has been tested with the following setup:

- STK1000 development kit
- AP7000 top board for STK1000 development kit

## Setup Information

CPU speed: 20 MHz

This example uses the switches, LEDs and RGB LEDs on the STK1000 card. They must be connected by the following scheme for the example to work out of the box.

- The header LED must be connected with a flat ribbon cable to J3 on GPIO
- The header RGB must be connected with a flat ribbon cable to J6 on GPIO
- The header SWITCH must be connected with a flat ribbon cable to J1 on GPIO

This example uses chip select signal 0, which is shared with the external DAC on the STK1000 development kit. This signal is pulled low when the microprocessor is active in master mode. And the same signal is used to signal the device while in slave mode.

The SPI buss located on the SPI header (J27) on the STK1000 board must be connected to anther target capable of SPI. For example an other STK1000 board or an Atmel AVR. It is nessesary to connect NPCS0 (chip select signal) on AP7000 for the application to work in slave mode.

## Application Usage

The device will start up in slave mode, and LED6 and LED0 on STK1000 board should be lit. If LED6 and LED0 is not lit there is a problem with setup or the CPU is not running.

The application is controlled using the switches on the STK1000 board. The switches have the following functions:

- SW7: change between master and slave mode
- SW5 (master mode): sends "Atmel AVR32 SPI test application\r\n" on SPI
- SW4 (master mode): sends "AVR32 SPI Atmel test application\r\n" on SPI
- SW3 (master mode): sends "This string is far to long to be used in Atmel AVR32 SPI test application\r\n"

SW5, SW4 and SW3 does not have any function in slave mode.

The application polls the SPI module in slave mode and will read all data sent on the SPI bus if NPSC0 is pulled low.

### Slave mode

When receiving data on the SPI bus the LED1 will blink for a very short periode and then LED3 will be lit while the device is comparing the text string received with the expected text string. At the same time as LED3 is lit the RGB LEDs will blink orange.

After the compare the status will be displayed using the RGB LEDs. The RGB LEDs have the following status:

- Green - string received was identical to compared string
- Red - string received was not identical to compared string
- Blinking red - received data was larger than receive buffer

The blinking red mode will usually follow by a new analyse mode since the application breaks the processing and there is often still data in the SPI receive register. I.e. normally there will first be blinking orange, then blinking red, then blinking orange and then continously red.

### Master mode

When SW5, SW4 or SW3 switch is pressed, a text string is sent on the SPI bus. While sending LED1 will be active on the STK1000 board.

## Contact Info

For more info about Atmel AVR32 visit Atmel AVR32
AVR32 Application Notes
Support mail: avr32@atmel.com