Bit-Bang
Bit-banging is a process where one emulates an unavailable peripheral using direct port manipulation commands on GPIO pins.
Last updated
Was this helpful?
Bit-banging is a process where one emulates an unavailable peripheral using direct port manipulation commands on GPIO pins.
Last updated
Was this helpful?
This article concerns digital protocol emulation. For the similar-sounding but generally unrelated topic of controlling a system, see .
A common example of this process would be the Arduino library, which emulates additional on a microcontroller with only one in hardware.
Some microcontrollers may have a limited number of key peripherals, or may map them to pins required for other purposes. If for any reason a peripheral of the correct type is unavailable, bit-banging is an alternative for many protocols. is the easiest protocol to bit-bang, as it is synchronous and therefore resistant to slight timing changes caused by interrupt execution. However, using clever programming with hardware timers, USARTs and can be emulated as well. Unusual or custom protocols must often also be bit-banged.
When emulating a peripheral, the timing requirements must carefully be examined to ensure that any interruptions caused by other events will not corrupt data. Interrupts may need to be disabled during certain critical sections. If an unused timer module is available, its output compare or input capture methods can perform precisely timed operations and allow the program to get to them when it has time.
As the lacks an accessible SPI port, SPI can be easily implemented by bit-banging. A trivial example is shown below; better performance can be achieved with a kernel-mode driver.
(Purdue SIGBots)