AVR library
Macros | Functions
spi.c File Reference

SPI routines. More...

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "spi.h"
#include "swdefs.h"
#include "hwdefs.h"


#define SPCR0   SPCR
#define SPE0   SPE
#define MSTR0   MSTR
#define SPSR0   SPSR
#define SPDR0   SPDR
#define SPIF0   SPIF


void spi_init (uint8_t fdiv)
 Initialize SPI interface. More...
uint8_t spi_rw (uint8_t d)
 Send and receive byte (NSS not controlled) More...
 ISR (SPI_STC_vect)

Detailed Description

SPI routines.

SPI methods are not interrupt driven - they wait until SPI operation completes. If you're using CMT and would prefer switching to another task while SPI operation is in progress, you can define SPI_USE_CMT in swdefs.h. This requires CMT_MUTEX_FUNC.

Also, SS (CS) is not controlled by these methods. It's the responsibility of the user.

Matej Kogovsek (matej.nosp@m.@ham.nosp@m.radio.nosp@m..si)
This file is part of mat-stm32f1-lib

Function Documentation

void spi_init ( uint8_t  fdiv)

Initialize SPI interface.

Although SPI can have different clock phase and polarity, I have never ran across anything that uses other than low polarity and 1st edge phase. Therefore these parameters are implied and not variable. As are 8 bit words and MSB first.

[in]fdivBaudrate prescaler, F_CPU dependent
uint8_t spi_rw ( uint8_t  d)

Send and receive byte (NSS not controlled)

[in]dByte to send
byte received