user23860: I'm working with Arduino boards with AVR C coding to perform simple SPI communication from master for simple blink application on slave side.
They don't work, the TX function on the master side doesn't seem to work, after serial monitor debugging is discovered the function never get over the while loop! Why is that?
Here are the codes I worked on last night:
Master:
/* nano board is the Master and transmit
  data to slave to blink LEDs */

void SPI_Init(void);
void SPI_TX(uint8_t data);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//start Serial
  Serial.println("Setting Up");
  void SPI_Init();
  delay(100);
  Serial.println("SPI intialization is complete");
}

void loop() {
  uint8_t d = 0x20;
  SPI_TX(d);
  Serial.println("just sent the 1st byte");
  _delay_ms(400);
  d = 01;
  SPI_TX(d);
  Serial.println("just sent the 2nd byte");
  _delay_ms(400);
}

void SPI_Init(void)
{
  DDRB = (1 << DDB3) | (1 << DDB1); // DDB2 MOSI, DDB1 SCK
  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0);
}

void SPI_TX(uint8_t data)
{
  SPDR = data;
  while (!(SPSR & (1 << SPIF)));
}

-------------------------------------------------------------- -

Slave:
-------------------------------------------------------------- -

/* pro micro as slave and receives data then push them on
  PORTD and PORTB to blink LEDs */

void SPI_Init_S(void);
void SPI_RX(void);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//start Serial
  Serial.println("Setting Up");
  SPI_Init_S();
  delay(100);
  Serial.println("SPI intialization is complete");
  DDRD = (1 << DDD5); // TX LED as output
  DDRB = (1 << DDB0); // RX LED as output
}

void loop() {
  // put your main code here, to run repeatedly:
  SPI_RX();
  PORTD = SPDR;   // blink the TX LED on pro micro board
  _delay_ms(500);
  SPI_RX();
  PORTB = SPDR;   // blink the RX LED on pro micro board
  _delay_ms(500);
}

void SPI_Init_S(void)
{
  SPCR = (1 << SPE) | (1 << SPR0);
}

void SPI_RX(void)
{
  return SPDR;
}


user10794: 
 void setup() {
// put your setup code here, to run once:
 Serial.begin(9600);//start Serial
 Serial.println("Setting Up");
 void SPI_Init(void);   // <---------------- this is wrong!
 delay(100);
 Serial.println("SPI intialization is complete");
 }


That isn't how you call a function.
It should read:
SPI_Init ();


23860: <p>I'm working with Arduino boards with AVR C coding to perform simple SPI communication from master for simple blink application on slave side.</p>

<p>They don't work, the TX function on the master side doesn't seem to work, after serial monitor debugging is discovered the function never get over the while loop! Why is that?</p>

<p>Here are the codes I worked on last night:</p>

<p>Master:</p>

<pre><code>/* nano board is the Master and transmit
  data to slave to blink LEDs */

void SPI_Init(void);
void SPI_TX(uint8_t data);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//start Serial
  Serial.println("Setting Up");
  void SPI_Init();
  delay(100);
  Serial.println("SPI intialization is complete");
}

void loop() {
  uint8_t d = 0x20;
  SPI_TX(d);
  Serial.println("just sent the 1st byte");
  _delay_ms(400);
  d = 01;
  SPI_TX(d);
  Serial.println("just sent the 2nd byte");
  _delay_ms(400);
}

void SPI_Init(void)
{
  DDRB = (1 &lt;&lt; DDB3) | (1 &lt;&lt; DDB1); // DDB2 MOSI, DDB1 SCK
  SPCR = (1 &lt;&lt; SPE) | (1 &lt;&lt; MSTR) | (1 &lt;&lt; SPR0);
}

void SPI_TX(uint8_t data)
{
  SPDR = data;
  while (!(SPSR &amp; (1 &lt;&lt; SPIF)));
}

-------------------------------------------------------------- -
</code></pre>

<p>Slave:</p>

<pre><code>-------------------------------------------------------------- -

/* pro micro as slave and receives data then push them on
  PORTD and PORTB to blink LEDs */

void SPI_Init_S(void);
void SPI_RX(void);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//start Serial
  Serial.println("Setting Up");
  SPI_Init_S();
  delay(100);
  Serial.println("SPI intialization is complete");
  DDRD = (1 &lt;&lt; DDD5); // TX LED as output
  DDRB = (1 &lt;&lt; DDB0); // RX LED as output
}

void loop() {
  // put your main code here, to run repeatedly:
  SPI_RX();
  PORTD = SPDR;   // blink the TX LED on pro micro board
  _delay_ms(500);
  SPI_RX();
  PORTB = SPDR;   // blink the RX LED on pro micro board
  _delay_ms(500);
}

void SPI_Init_S(void)
{
  SPCR = (1 &lt;&lt; SPE) | (1 &lt;&lt; SPR0);
}

void SPI_RX(void)
{
  return SPDR;
}
</code></pre>
 10794: <blockquote>
<pre><code> void setup() {
// put your setup code here, to run once:
 Serial.begin(9600);//start Serial
 Serial.println("Setting Up");
 void SPI_Init(void);   // &lt;---------------- this is wrong!
 delay(100);
 Serial.println("SPI intialization is complete");
 }
</code></pre>
</blockquote>

<p>That isn't how you call a function.</p>

<p>It should read:</p>

<pre><code>SPI_Init ();
</code></pre>
