Hardware and software spi

I've started research on the spi communication method and so far it is stated that there are two types of spi communication whitch are software and hardware. The main difference between the two seems to be the speed with hardware spi being faster.
Obviously there should also be a difference in the code of two types, but i just cant example codes :sweat_smile:, so if anyone know where i can find example codes of both please share a link.

I also wanted to know if using the spi libray "include<SPI.H>" meant that i was using sofware spi?
Are pins 13,11 and 10 only used in hardware spi, or does the library also use them?

As you can see i'm very confused about the subject, any answers would be appreciated

Thank you

If you include SPI.H, then you are including the code library to use the hardware SPI interface built into your micro.

Pins 11, 12 & 13 (on an UNO board) are used by the hardware SPI interface along with pin 10. So if you include SPI.H, then, keeping it simple, you have to use these 4 pins.

If you use a software SPI implementation, then the software SPI library may allow you to specify which pins to use for each of the SPI signals.

A quick google search for "Arduino software SPI" showed up several hits.

this is a very useful answer thank you a lot !!!!!

I also wanted to clarify something.

Is this some older way of writhing the spi transfer function instead of using the spi.transfer() function that is already provided by the library.

I assume they do the same thing and are interchangeable, right?

byte spi_transfer(byte data) {
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte. (we don't need that here)
}

Hello m5,
it is not an older way. It is the software low level code by writing directly to the register of the processor. You can do this too if you like, then you have to read the Atmega328 handbook and search for the SPI topic. If you do not like the writing to registers then you can use the high level spi.transfer(). This function will handle the writing to registers for you. Best regards Markus

There's also this method ...
Using the Master SPI Mode of the USART module

thanks to everyone for the very helpful answers!!!!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.