Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

embedded

i2c

spi

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

like image 933
anujdeshpande Avatar asked Dec 26 '13 19:12

anujdeshpande


People also ask

What are the primary disadvantages of bit banging?

Disadvantages of Bit Banging Compared to dedicated hardware, more communication errors like glitches and jitters occur when bit banging is used especially when data communication is being performed by the microcontroller at the same time as other tasks.

What is bit banging in SPI?

Bit banging allows a device to implement different protocols with minimal or no hardware changes. In some cases, bit banging is made feasible by newer, faster processors because more recent hardware operates much more quickly than hardware did when standard communications protocols were created.

What is the difference between peripheral and bit banging method?

A peripheral will offload the CPU to do other things while talking to the flash whereas bit bit banging involves builtin delays and code execution between bits. Besides, you an use an interrupt to handle the SPI completion rather than babysitting the hardware.


2 Answers

Bit-banging carries a software overhead consuming CPU cycles that you could otherwise utilise for other purposes. This may have a noticeable effect on system responsiveness to other events, and in a hard real-time system, may significantly impact the systems ability to meet real-time deadlines.

If the bit-banged interface is not to have a detrimental effect on real-time performance, then it must be given low priority so will then itself be non-deterministic in terms of data throughput and latency.

The most CPU efficient transfer is achieved by using a hardware interface and DMA transfer to minimise the software overhead. Bit-banging is at the opposite extreme of that.

I would not say it was horrible; if in your application you can achieve responsiveness and real-time constraints and the use of bit-banging perhaps reduces the cost of the part needed or allows you to use existing hardware for example, then it may be entirely justified.

like image 134
Clifford Avatar answered Oct 12 '22 11:10

Clifford


Bit banging is portable, see the I2C code in the Linux kernel drivers for example. You can get it up and running quickly and it just works. Hardware based solutions generally are not and take a while to get up and running and are limited by the hardware implementation. Not all spi and in particular i2c conform to a standard that can be implemented in a generic hardware solution. You must always be able to fall back on bit banging.

Bit banging consumes more processor resources, that makes it undesirable from that front. It is more portable or can be depending on how it is written, so it is desirable on that front. Hardware SPI/I2C is the opposite of those, takes away some of the cpu overhead, is not portable, is not always flexible enough to handle all peripherals.

As a professional you need to be comfortable with both, just like any other embedded tradeoff you make in your design.

like image 24
old_timer Avatar answered Oct 12 '22 10:10

old_timer