Search code examples
cstm32spi

Software SPI Implementation


I'm thinking about creating my own pure-C software SPI library because there are none available (as far as I can tell).

Which also worries me - why aren't there any software SPI libraries? Is there some hardware limitation I'm not considering?

EDIT:

I've decided to write my own library due to how buggy the SPI peripheral is in STM32. Especially in 8 bit mode, but I've also had a lot of problems with 16 bit mode. Many other issues I didn't even bother documenting.

I've now written the software implementation (it is pretty easy) and in works just fine.


Solution

  • why aren't there any software SPI libraries?

    Because it's about 10 lines of code each for the WriteByte and ReadByte functions, and most of that is bit banging processor-specific registers. The higher level protocol depends on the device connected to the SPI. Here's what wikipedia has to say on the subject

    The SPI bus is a de facto standard. However, the lack of a formal standard is reflected in a wide variety of protocol options. Different word sizes are common. Every device defines its own protocol, including whether or not it supports commands at all. Some devices are transmit-only; others are receive-only. Chip selects are sometimes active-high rather than active-low. Some protocols send the least significant bit first.

    So there's really no point in making a library. You just write the code for each specific situation, and combination of devices.