OpenCores
URL https://opencores.org/ocsvn/igor/igor/trunk

Subversion Repositories igor

[/] [igor/] [trunk/] [avr/] [src/] [dev/] [spi.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 atypic
#include "spi.h"
2
#include <avr/io.h>
3
 
4
//Configure the SPI interface for use with SD/MMC and Ethernet
5
void configure_spi(void)
6
{
7
        //Set pins as output
8
        SPI_DDR |= (1<<SPI_SCK) | (1<<SPI_MOSI) | (1<<SPI_SS_MMC) | (1<<SPI_SS_ETHERNET);
9
 
10
        //Set pins as input
11
        SPI_DDR &= ~(1<<SPI_MISO);
12
 
13
        //Activate pull-up on MISO and set both SS lines high (deasserted)
14
        SPI_PORT |= (1<<SPI_MISO) | (1<<SPI_SS_MMC) | (1<<SPI_SS_ETHERNET);
15
 
16
        //Drive SCK and MOSI low
17
        SPI_PORT &= ~((1<<SPI_SCK) | (1<<SPI_MOSI));
18
 
19
        // Disable SPI powersaving
20
        PRR0 &= ~(1<<PRSPI);
21
 
22
        /*Configure SPI interface:
23
        * Disable SPI interrupts
24
        * Enable SPI
25
        * Set data order MSB first
26
        * Set SPI master mode
27
        * Set clock polarity idle low
28
        * Set clock phase to sample on rising edge
29
        * Set SPI speed to freq_cpu/4
30
        */
31
        SPCR = (0<<SPIE)|(1<<SPE)|(0<<DORD)|(1<<MSTR)|(0<<CPOL)|(0<<CPHA)|(0<<SPR1)|(0<<SPR0);
32
 
33
        //Activate SPI2X, doubling the speed set in the previous register
34
        SPSR = (1<<SPI2X);
35
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.