What are the disadvantages of bit banging SPI/I2C in embedded applications

前端 未结 5 780
天涯浪人
天涯浪人 2021-01-05 23:30

I have come to understand that bit banging is horrible practice when it comes to SPI/I2C over GPIO. Why so?

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-06 00:26

    I don't know that it's horrible, but if you have SPI or I2C peripherals already available, there's certainly a "don't reinvent the wheel" argument to be made against bit-banging, especially as you might have a bug in your code - for example you might be sampling on the wrong edge of the SPI clock, and depending on the tolerances involved and what hardware you test with, you might not notice it until you're already in production. The wikipedia article also notes that you're using extra processing power and that you're probably going to to introduce jitter into any signals you produce.

    All that said, bit-banging is the only choice available if your hardware doesn't have a built-in peripheral, or if it's already used up by other devices, e.g. if the built-in SPI peripheral is used by a high-bandwidth device that you have to continuously communicate with, maybe you bit bang to another SPI device that doesn't need to be so real-time in your application.

提交回复
热议问题