-4

For my thesis I'm using an ATmega16 to communicate with MCP2515 over SPI. When we are checking the example code to set up SPI as a slave mode in the Atmega16 datasheet we get next example code.

void SPI_SlaveInit(void)
{
/* Set MISO output, all others input */
    DDR_SPI = (1<<DD_MISO);
/* Enable SPI */
    SPCR = (1<<SPE);
}
char SPI_SlaveReceive(void)
{
/* Wait for reception complete */
    while(!(SPSR & (1<<SPIF)))
;
/* Return data register */
    return SPDR;
}

We don't understand why they are using char SPI_SlaveReceive(void) instead of just void SPI_SlaveReceive(void). Can somebody explain us why they use the char instead of void? What is the difference? I can't find a good explanation on the internet.

asu
  • 1,875
  • 17
  • 27
TMJ
  • 71
  • 1
  • 1
  • 7

1 Answers1

1

SPI_SlaveReceive receives something, so it's returning that "something" as a char, hence the return type. If it was typed to return void you wouldn't be able to get the received value, which wouldn't be very useful!

If it didn't return what it received how would you ever get what was received..?

Sean
  • 60,939
  • 11
  • 97
  • 136