SPI for avr

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does anyone know where I can find an example in C code about SPI for avr?

Thanks!

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try avr335 application Note on Atmel's Website.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try http://www.myplace.nu/mp3/. SPI; I2C, ATA....

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

/* #define SPI_MASTER_SETUP() \ { SPCR = 0x80 | 0x40 | 0x10 | 0x04 | 0x00; } */
/*SPCR = SPIE | SPE | MSTR | CPHA | SPR1_0_4; _SEI(); }*/
#define SPI_send(data) SPDR = data; for(;!spi_flag;); spi_flag=0;
void SPI_SEND_RECEIVE()
{
typedef union
{
int x;
char y[2];
} SPI_Value;
SPI_Value Value;

SPCR = 0x80 | 0x40 | 0x10 | 0x08 | 0x04 ; /* | 0x08 | 0x04*/
SPI_send(0xFF);
Value.y[1] = spi_data;
SPI_send(0xFF);
Value.y[0] = spi_data;
}
// receive 16 bits back from external source
// most of this came from Atmel.

admin's test signature