title: SPI not working on atmega328p
body: <p>I'm trying to program an atmega328p, but the SPI bus isn't working. It's not sending any data over the bus. </p>
  
  <p>My code is as follows:</p>
  
  <pre><code>#include &lt;asf.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;main.h&gt;
  
  int main (void)
  {
      board_init();
      SPI_MasterInit();
  
      DDRD = (1&lt;&lt;DDD5);
  
      while(1)
      {
          PORTB &amp;= ~(1&lt;&lt;DDB2);
          SPI_MasterTransmit(0xAB);
          PORTB |= (1&lt;&lt;DDB2);
  
          PORTD ^= (1&lt;&lt;DDD5);
      }
  }
  
  void SPI_MasterInit(void)
  {
      /* Set MOSI and SCK output, all others input */
      DDRB = (1&lt;&lt;5) || (1&lt;&lt;3) || (1&lt;&lt;2);
      /* Enable SPI, Master, set clock rate fck/16 */
      SPCR = (1&lt;&lt;SPE)|(1&lt;&lt;MSTR)|(1&lt;&lt;SPR0);
  }
  
  void SPI_MasterTransmit(char cData)
  {
      /* Start transmission */
      SPDR = cData;
      /* Wait for transmission complete */
      while(!(SPSR &amp; (1&lt;&lt;SPIF)));
  }
  </code></pre>
  
  <p>I'm trying to send some random data over the bus (0xAB) to check if the bus works properly so I can add further code. In the while loop I also set a pin. </p>
  
  <p>On my scope image I see no data being send on the SPI pin MOSI and the CLK pin is also not sending information. PB5 (the pin I'm inverting everytime I try to send data) is working and has a period of about 20 microseconds. </p>
  
  <p>I'm programming the Atmega328p through an Atmel ICE. The programming interface is also through SPI, I read somewhere that this might be an issue. I'm not completely sure.</p>
  
  <p>Does anyone know what might be the problem?</p>