3.2 Bit Banging

Bit banging refers to any implementation of serial communication which is directly driven by software. Instead of using a dedicated peripheral, the software reads and writes the input and input pins, and handles timing.

Delay routines can be used to handle bus timing. Delay routines are busy-wait loops which count a predefined number of CPU clock cycles. When a delay routine has finished, the CPU will take some action on the pin used for communication, such as sampling the pin, toggling the pin output, or changing the pin from an output to an input pin.

When executing delay routines, the CPU cannot do other tasks. Interrupt service routines (ISRs) will have to wait until the CPU is done with the bit banging. Because of this, the CPU cycles used by the ISR will not be correctly subtracted from the delay routine, and signal timing will not be correct. In the case of the 1-Wire protocol, this gives a worst-case interrupt latency of almost 1 ms.

Arduino® implements the 1-Wire protocol on the AVR using bit banging. When bit banging 1-Wire, an open-drain or open-collector circuit is not necessary. Instead, the pin direction is switched from output to input depending on if the protocol demands transmission or reception of data.