Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1. #ifndef SPI_H_
  2. #define SPI_H_
  3.  
  4. #include <inttypes.h>
  5. #include <avr/io.h>
  6.  
  7. #define SPIPORT PORTB
  8. #define SPIPIN  PINB
  9. #define SPIDDR  DDRB
  10.  
  11. #if defined(__AVR_ATmega8__)
  12. #define SPISCK   PB5  
  13. #define SPIMISO  PB4
  14. #define SPIMOSI  PB3  
  15. #define SPISS    PB2
  16. #elif defined(__AVR_ATmega32__) || defined(__AVR_ATmega16__)
  17. #define SPISCK   PB7
  18. #define SPIMISO  PB6
  19. #define SPIMOSI  PB5  
  20. #define SPISS    PB4
  21. #else
  22. #error "SPI pins undefined for this target"
  23. #endif
  24.  
  25. #define SPI_SS_HIGH() (SPIPORT |= (1<<SPISS))
  26. #define SPI_SS_LOW() (SPIPORT &= ~(1<<SPISS))
  27.  
  28. void spi_init(void);
  29. uint8_t spi_readwrite(uint8_t data);
  30. uint8_t spi_read(void);
  31.  
  32. #endif
  33.  
  34.