title: SPI initializing in Atmel studio
body: <p>im trying to use my Micro OLED Sparkfun display (here is the datasheet <a href="https://i.stack.imgur.com/xIahd.png" rel="nofollow noreferrer">enter link description here</a>) but i have a problem about code. Maybe is the problem in code because im working first time with SPI in Atmel so if would be somebody so nice and check it out, give me some advices about i will be so thankful.</p>
  
  <p>EDIT: Here is the changed code and picture of display wires</p>
  
  <pre><code>#define F_CPU 16000000
   #include &lt;avr/io.h&gt;
   #include &lt;util/delay.h&gt;
   #define SCK DDB5
   #define SDIN DDB3
   #define D_C DDB0
   #define CS DDB2
   #define RST DDB1
  
   void SPI_MasterInit(void)
   {
       /* Set MOSI and SCK output, all others input */
       DDRB = (1&lt;&lt;SCK)|(1&lt;&lt;SDIN)|(1&lt;&lt;D_C)|(1&lt;&lt;CS)|(1&lt;&lt;RST);
       /* Enable SPI, Master, set clock rate fck/16 */
       PORTB |= (1&lt;&lt;CS);
       PORTB |= (1&lt;&lt;D_C);
       SPCR = (1&lt;&lt;SPE)|(1&lt;&lt;MSTR)|(1&lt;&lt;SPR0)|(0&lt;&lt;DORD);
   }
   void SPI_MasterTransmit_Command(int cCommand)
   {
       PORTB &amp;= ~(1&lt;&lt;CS);
       PORTB &amp;= ~(1&lt;&lt;D_C);
       _delay_ms(200);
       /* Start transmission */
       SPDR = cCommand;
       /* set dc and cs low to send command */
       /* Wait for transmission complete */
       while(!(SPSR &amp; (1&lt;&lt;SPIF)));
       /* set dc cs high again */
       PORTB |= (1&lt;&lt;CS);
       PORTB |= (1&lt;&lt;D_C);
  
  
   }
  
   void Display_ON(void)
   {
       PORTB &amp;= ~(1&lt;&lt;RST);
       _delay_ms(50);
       PORTB |= (1&lt;&lt;RST);
       _delay_ms(50);
       PORTB &amp;= ~(1&lt;&lt;RST);
       _delay_ms(50);
       SPI_MasterTransmit_Command(0xAF);
       _delay_ms(200);
   }
  
   int main(void)
   {
       SPI_MasterInit();
       Display_ON();
       SPI_MasterTransmit_Command(0xA5);
  
   }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xIahd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xIahd.png" alt="enter image description here"></a></p>