TheLegace

Dragon12_SPI

Mar 28th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. /***********************************************************************************
  2.  
  3.   York University CSE3215
  4.   Main.c
  5.   Jan 09, 2006
  6.  
  7. ***********************************************************************************/
  8. #include <hidef.h>            /* common defines and macros */
  9. #include <mc9s12dp256.h>      /* MicroController derivative information */
  10.  
  11.  
  12. #pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
  13.  
  14. void main(void) {
  15.  
  16. volatile byte data;
  17.  
  18. //PLL_init();  // set system clock frequency to 24 MHz
  19.  
  20.   EnableInterrupts;
  21.   // SPI communication initialization as a master
  22.   SPI0BR  = 0b00000011;    // Baud rate = 24MHz/16 = 1.5MHz 0x53;
  23.   SPI0CR2 = 0b00010000;  // SPI0CR2_SPISWAI=1 : Stop SPI clocks when in wait mode
  24.   SPI0CR1 = 0b01010110;  // Enable SPI ; Master mode ; CPHA = 1 ;
  25.  
  26.   WOMS = 0;
  27.  
  28.                                                  // SSOE=1 (SS input with MODF feature)      
  29.   /*DDRS |= 0x61;   // 0b 0 1 1 0 0 0 0 1 : PS7(SS) and PS4(MISO) are input and PS6(SCK)
  30.  
  31.                                // and PS5(MOSI) are output, PS0 is output for setting and clearing slave's SS
  32.  
  33.   PTS &= (~0x01);                  // Low slave's SS*/
  34.  
  35.  
  36.   for( ; ; ){  
  37.    
  38.     //PTS &= (~0x01);              // Low slave's SS
  39.                
  40.     // Send a byte to the slave
  41.     while( SPI0SR_SPTEF == 0); // Wait until SPIDR becomes empty.
  42.     SPI0DR = 0x04;                         //  Clear the flag SPI0SR_STEF
  43.  
  44.     while( SPI0SR_SPIF == 0 );   // Wait until the end of an SPI transfer.  
  45.     data = SPI0DR;                        // Read or write to clear SPI0SR_SPIF flag      
  46.    
  47.        
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment