Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <platform.h>
  2. #include "SPI_Master/spi_master.h"
  3. #include <print.h>
  4.  
  5. #define SPI_CS XS1_PORT_4A
  6. #define SPI_MOSI XS1_PORT_1D
  7. #define SPI_CLK XS1_PORT_1C
  8. #define SPI_MISO XS1_PORT_1B
  9.  
  10. out port SPI_ChipSelect = SPI_CS;
  11.  
  12. const char read_id = 0x9F;
  13. unsigned word;
  14.  
  15. spi_master_interface spi_if = { XS1_CLKBLK_1, XS1_CLKBLK_2, PORT_SPI_MOSI,
  16. PORT_SPI_CLK, PORT_SPI_MISO };
  17.  
  18. void spi_deselect();
  19. void spi_select();
  20.  
  21. int main(void) {
  22. spi_init(spi_if, 4);
  23. spi_deselect();
  24.  
  25.  
  26. spi_select();
  27. word = spi_in_word(spi_if);
  28. spi_deselect();
  29.  
  30. printhex(word);
  31.  
  32. spi_shutdown(spi_if);
  33.  
  34. }
  35.  
  36. void spi_select() {
  37. SPI_ChipSelect <: 0;
  38. }
  39.  
  40. void spi_deselect() {
  41. SPI_ChipSelect <: 0b1111;
  42. }