- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# spi_drv.h File Reference

SPI Low level drivers access. More...

`#include "config.h"`

Include dependency graph for spi_drv.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Defines
#define | MSK_SPI_MODE ((1<<CPOL)|(1<<CPHA))
#define | MSK_SPI_CPHA_LEADING (0<<CPHA)
#define | MSK_SPI_CPHA_TRAILING (1<<CPHA)
#define | MSK_SPI_CPOL_LOW (0<<CPOL)
#define | MSK_SPI_CPOL_HIGH (1<<CPOL)
#define | SPI_MODE_0 (MSK_SPI_CPOL_LOW|MSK_SPI_CPHA_LEADING)
#define | SPI_MODE_1 (MSK_SPI_CPOL_LOW|MSK_SPI_CPHA_TRAILING)
#define | SPI_MODE_2 (MSK_SPI_CPOL_HIGH|MSK_SPI_CPHA_LEADING)
#define | SPI_MODE_3 (MSK_SPI_CPOL_HIGH|MSK_SPI_CPHA_TRAILING)
#define | MSK_SPI_MULT2 0x80
#define | MSK_SPR ((1<<SPR1)|(1<<SPR0))
#define | MSK_SPI_DIV4 ((0<<SPR1)|(0<<SPR0))
#define | MSK_SPI_DIV16 ((0<<SPR1)|(1<<SPR0))
#define | MSK_SPI_DIV64 ((1<<SPR1)|(0<<SPR0))
#define | MSK_SPI_DIV128 ((1<<SPR1)|(1<<SPR0))
#define | SPI_RATE_0 (MSK_SPI_MULT2|MSK_SPI_DIV4)
#define | SPI_RATE_1 (MSK_SPI_DIV4)
#define | SPI_RATE_2 (MSK_SPI_MULT2|MSK_SPI_DIV16)
#define | SPI_RATE_3 (MSK_SPI_DIV16)
#define | SPI_RATE_4 (MSK_SPI_MULT2|MSK_SPI_DIV64)
#define | SPI_RATE_5 (MSK_SPI_DIV64)
#define | SPI_RATE_6 (MSK_SPI_DIV128)
#define | Spi_enable() (SPCR |= (1<<SPE))
#define | Spi_disable() (SPCR &= ~(1<<SPE))
#define | Spi_enable_it() (SPCR |= (1<<SPIE))
#define | Spi_disable_it() (SPCR &= ~(1<<SPIE))
#define | Spi_select_slave() (SPCR &= ~(1<<MSTR))
#define | Spi_select_master() (SPCR |= (1<<MSTR))
#define | Spi_set_lsbfirst() (SPCR |= (1<<DORD))
#define | Spi_set_msbfirst() (SPCR &= ~(1<<DORD))
#define | Spi_set_mode(mode) {SPCR &= ~MSK_SPI_MODE; SPCR |= mode;}
#define | Spi_set_rate(rate) {SPCR &= ~MSK_SPR; SPCR |= rate&MSK_SPR; (rate & MSK_SPI_MULT2)? Spi_set_doublespeed() : Spi_clear_doublespeed();}
#define | Spi_set_doublespeed() (SPSR |= (1<<SPI2X))
#define | Spi_clear_doublespeed() (SPSR &= ~(1<<SPI2X))
#define | Spi_init_bus() ((DDRB |= (1<<DDB2)|(1<<DDB1)))
#define | Spi_disable_ss()
#define | Spi_enble_ss()
#define | Spi_wait_spif() while ((SPSR & (1<<SPIF)) == 0)
#define | Spi_wait_eor() while ((SPSR & (1<<SPIF)) == 0)
#define | Spi_wait_eot() while ((SPSR & (1<<SPIF)) == 0)
#define | Spi_eor() ((SPSR & (1<<SPIF)) == (1<<SPIF))
#define | Spi_eot() ((SPSR & (1<<SPIF)) == (1<<SPIF))
#define | Spi_is_colision() (SPSR&(1<<WCOL))
#define | Spi_get_byte() (SPDR)
#define | Spi_tx_ready() (SPSR & (1<<SPIF))
#define | Spi_rx_ready() Spi_tx_ready()
#define | Spi_ack_read() (SPSR)
#define | Spi_ack_write() (SPDR)
#define | Spi_ack_cmd() (SPSR)
#define | Spi_read_data() (SPDR)
#define | Spi_write_data(byte) {(SPDR=byte);Spi_wait_spif();}

## Detailed Description

SPI Low level drivers access.

- Compiler: IAR EWAVR and GNU GCC for AVR
- Supported devices: AT90USB1287, AT90USB1286, AT90USB647, AT90USB646

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file spi_drv.h.

## Define Documentation

#define MSK_SPI_MODE ((1<<CPOL)|(1<<CPHA))

Definition at line 52 of file spi_drv.h.

#define MSK_SPI_CPHA_LEADING (0<<CPHA)

Definition at line 53 of file spi_drv.h.

#define MSK_SPI_CPHA_TRAILING (1<<CPHA)

Definition at line 54 of file spi_drv.h.

#define MSK_SPI_CPOL_LOW (0<<CPOL)

Definition at line 55 of file spi_drv.h.

#define MSK_SPI_CPOL_HIGH (1<<CPOL)

Definition at line 56 of file spi_drv.h.

#define SPI_MODE_0 (MSK_SPI_CPOL_LOW|MSK_SPI_CPHA_LEADING)

Definition at line 57 of file spi_drv.h.

#define SPI_MODE_1 (MSK_SPI_CPOL_LOW|MSK_SPI_CPHA_TRAILING)

Definition at line 58 of file spi_drv.h.

#define SPI_MODE_2 (MSK_SPI_CPOL_HIGH|MSK_SPI_CPHA_LEADING)

Definition at line 59 of file spi_drv.h.

#define SPI_MODE_3 (MSK_SPI_CPOL_HIGH|MSK_SPI_CPHA_TRAILING)

Definition at line 60 of file spi_drv.h.

Referenced by df_init().

#define MSK_SPI_MULT2 0x80

Definition at line 63 of file spi_drv.h.

#define MSK_SPR ((1<<SPR1)|(1<<SPR0))

Definition at line 64 of file spi_drv.h.

#define MSK_SPI_DIV4 ((0<<SPR1)|(0<<SPR0))

Definition at line 65 of file spi_drv.h.

#define MSK_SPI_DIV16 ((0<<SPR1)|(1<<SPR0))

Definition at line 66 of file spi_drv.h.

#define MSK_SPI_DIV64 ((1<<SPR1)|(0<<SPR0))

Definition at line 67 of file spi_drv.h.

#define MSK_SPI_DIV128 ((1<<SPR1)|(1<<SPR0))

Definition at line 68 of file spi_drv.h.

#define SPI_RATE_0 (MSK_SPI_MULT2|MSK_SPI_DIV4)

Definition at line 69 of file spi_drv.h.

Referenced by df_init().

#define SPI_RATE_1 (MSK_SPI_DIV4)

Definition at line 70 of file spi_drv.h.

#define SPI_RATE_2 (MSK_SPI_MULT2|MSK_SPI_DIV16)

Definition at line 71 of file spi_drv.h.

#define SPI_RATE_3 (MSK_SPI_DIV16)

Definition at line 72 of file spi_drv.h.

#define SPI_RATE_4 (MSK_SPI_MULT2|MSK_SPI_DIV64)

Definition at line 73 of file spi_drv.h.

#define SPI_RATE_5 (MSK_SPI_DIV64)

Definition at line 74 of file spi_drv.h.

#define SPI_RATE_6 (MSK_SPI_DIV128)

Definition at line 75 of file spi_drv.h.

#define Spi_enable | ( |  | ) | (SPCR |= (1<<SPE))

Definition at line 81 of file spi_drv.h.

Referenced by df_init().

#define Spi_disable | ( |  | ) | (SPCR &= ~(1<<SPE))

Definition at line 82 of file spi_drv.h.

#define Spi_enable_it | ( |  | ) | (SPCR |= (1<<SPIE))

Definition at line 85 of file spi_drv.h.

#define Spi_disable_it | ( |  | ) | (SPCR &= ~(1<<SPIE))

Definition at line 86 of file spi_drv.h.

#define Spi_select_slave | ( |  | ) | (SPCR &= ~(1<<MSTR))

Definition at line 89 of file spi_drv.h.

#define Spi_select_master | ( |  | ) | (SPCR |= (1<<MSTR))

Definition at line 90 of file spi_drv.h.

Referenced by df_init().

#define Spi_set_lsbfirst | ( |  | ) | (SPCR |= (1<<DORD))

Definition at line 91 of file spi_drv.h.

#define Spi_set_msbfirst | ( |  | ) | (SPCR &= ~(1<<DORD))

Definition at line 92 of file spi_drv.h.

#define Spi_set_mode | ( | mode |  | ) | {SPCR &= ~MSK_SPI_MODE; SPCR |= mode;}

Definition at line 93 of file spi_drv.h.

Referenced by df_init().

#define Spi_set_rate | ( | rate |  | ) | {SPCR &= ~MSK_SPR; SPCR |= rate&MSK_SPR; (rate & MSK_SPI_MULT2)? Spi_set_doublespeed() : Spi_clear_doublespeed();}

Definition at line 94 of file spi_drv.h.

Referenced by df_init().

#define Spi_set_doublespeed | ( |  | ) | (SPSR |= (1<<SPI2X))

Definition at line 95 of file spi_drv.h.

#define Spi_clear_doublespeed | ( |  | ) | (SPSR &= ~(1<<SPI2X))

Definition at line 96 of file spi_drv.h.

#define Spi_init_bus | ( |  | ) | ((DDRB |= (1<<DDB2)|(1<<DDB1)))

Definition at line 97 of file spi_drv.h.

Referenced by df_init().

#define Spi_disable_ss | ( |  | ) |

Definition at line 98 of file spi_drv.h.

Referenced by df_init().

#define Spi_enble_ss | ( |  | ) |

Definition at line 99 of file spi_drv.h.

#define Spi_wait_spif | ( |  | ) | while ((SPSR & (1<<SPIF)) == 0)

Definition at line 102 of file spi_drv.h.

#define Spi_wait_eor | ( |  | ) | while ((SPSR & (1<<SPIF)) == 0)

Definition at line 103 of file spi_drv.h.

#define Spi_wait_eot | ( |  | ) | while ((SPSR & (1<<SPIF)) == 0)

Definition at line 104 of file spi_drv.h.

#define Spi_eor | ( |  | ) | ((SPSR & (1<<SPIF)) == (1<<SPIF))

Definition at line 105 of file spi_drv.h.

#define Spi_eot | ( |  | ) | ((SPSR & (1<<SPIF)) == (1<<SPIF))

Definition at line 106 of file spi_drv.h.

#define Spi_is_colision | ( |  | ) | (SPSR&(1<<WCOL))

Definition at line 107 of file spi_drv.h.

#define Spi_get_byte | ( |  | ) | (SPDR)

Definition at line 108 of file spi_drv.h.

#define Spi_tx_ready | ( |  | ) | (SPSR & (1<<SPIF))

Definition at line 109 of file spi_drv.h.

#define Spi_rx_ready | ( |  | ) | Spi_tx_ready()

Definition at line 110 of file spi_drv.h.

#define Spi_ack_read | ( |  | ) | (SPSR)

Definition at line 111 of file spi_drv.h.

#define Spi_ack_write | ( |  | ) | (SPDR)

Definition at line 112 of file spi_drv.h.

Referenced by df_host_write_sector(), df_read_open(), df_wait_busy(), df_write_close(), df_write_open(), df_write_sector(), and df_write_sector_from_ram().

#define Spi_ack_cmd | ( |  | ) | (SPSR)

Definition at line 113 of file spi_drv.h.

#define Spi_read_data | ( |  | ) | (SPDR)

Definition at line 116 of file spi_drv.h.

Referenced by df_host_read_sector(), df_mem_check(), df_read_sector(), df_read_sector_2_ram(), and df_wait_busy().

#define Spi_write_data | ( | byte |  | ) | {(SPDR=byte);Spi_wait_spif();}

Definition at line 117 of file spi_drv.h.

Referenced by df_host_read_sector(), df_host_write_sector(), df_mem_check(), df_read_open(), df_read_sector(), df_read_sector_2_ram(), df_wait_busy(), df_write_close(), df_write_open(), df_write_sector(), and df_write_sector_from_ram().