Hello
Who could explain in simple word or concept the difference between these mode. What I see as difference is the for the hardware mode, you use the predefiined pin for your processor, but at the end it is or should be the same result.
Martin
Hello
Who could explain in simple word or concept the difference between these mode. What I see as difference is the for the hardware mode, you use the predefiined pin for your processor, but at the end it is or should be the same result.
Martin
SPI hardware is not just a pin. Microcontrollers have peripherals that will create all the needed signals. Your sketch writes a byte to a register and the peripheral shifts the bits out and receives new bits from the slave at the same time. Some can automatically send more data using other peripherals e.g. DMA without the processor doing anything.
Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices. Typically there are three lines common to all the devices (MISO, MOSI, SCK) and each slave has its own pin that the master can use to enable and disable specific devices.
The protocol requires precise handling of all those pins. A Hardware SPI means that the micro controller has a dedicated piece of hardware built in managing the protocol in the background for you.
A Software SPI means some software layer needs to run on the micro controller and will handle the hard work
Hardware SPI is much faster due to having dedicated internal hardware to shift the bits out.
With an 16 MHz system clock, an 8 MHz SPI clock can be selected and 8 bits shifted out in 17 clock cycles:
spdr = dataByte;
With software SPI, the code has to:
grab the first bit from a byte to be shifted out and put it on an output pin
write the clock pin high
write the clock pin low
repeat 7 more times.
Waaay slower.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.