Bit banging is a
term of art
Jargon, or technical language, is the specialized terminology associated with a particular field or area of activity. Jargon is normally employed in a particular communicative context and may not be well understood outside that context. The conte ...
that describes a method of
digital
Digital usually refers to something using discrete digits, often binary digits.
Businesses
*Digital bank, a form of financial institution
*Digital Equipment Corporation (DEC) or Digital, a computer company
*Digital Research (DR or DRI), a software ...
data transmission
Data communication, including data transmission and data reception, is the transfer of data, signal transmission, transmitted and received over a Point-to-point (telecommunications), point-to-point or point-to-multipoint communication chann ...
as using
general-purpose input/output (GPIO) instead of
computer hardware
Computer hardware includes the physical parts of a computer, such as the central processing unit (CPU), random-access memory (RAM), motherboard, computer data storage, graphics card, sound card, and computer case. It includes external devices ...
that is intended specifically for
data communication
Data communication, including data transmission and data reception, is the transfer of data, transmitted and received over a point-to-point or point-to-multipoint communication channel. Examples of such channels are copper wires, optic ...
.
Controlling
software
Software consists of computer programs that instruct the Execution (computing), execution of a computer. Software also includes design documents and specifications.
The history of software is closely tied to the development of digital comput ...
is responsible for satisfying
protocol requirement
In engineering, a requirement is a condition that must be satisfied for the output of a work effort to be acceptable. It is an explicit, objective, clear and often quantitative description of a condition to be satisfied by a material, design, pro ...
s including timing which can be challenging due to limited host
system resources and competing demands on the software.
In contrast, dedicated communication hardware (e.g.,
UART,
SPI,
I²C
I2C (Inter-Integrated Circuit; pronounced as "" or ""), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconduct ...
) satisfies protocol requirements which tends to reduce the
runtime load on the controlling system software and its host
processor. In particular, some communication hardware provides
data buffer
In computer science, a data buffer (or just buffer) is a region of memory used to store data temporarily while it is being moved from one place to another. Typically, the data is stored in a buffer as it is retrieved from an input device (such as ...
ing to lower the runtime load of the controlling system.
The bit banging method may allow a computer to support a protocol with limited or no hardware changes and therefore bit banging can be a lower cost option since changing software is typically less expensive than changing hardware.
Bit banging is commonly used in
embedded systems
An embedded system is a specialized computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is em ...
.
Choosing between bit banging and dedicated communication hardware involves
trade-offs between load, performance and reliability on one hand, and availability of hardware on the other. Bit banging consumes more processing resources than using dedicated hardware. The processor spends much of its time controlling data lines which precludes other processing. Also, bit banging typically results in a lower quality signal with more
jitter
In electronics and telecommunications, jitter is the deviation from true periodicity of a presumably periodic signal, often in relation to a reference clock signal. In clock recovery applications it is called timing jitter. Jitter is a signifi ...
and
glitches especially if the processor is performing other tasks simultaneously. However, if the software is interrupt-driven by the signal, the signal quality may be better, especially if control signals such as
RTS, CTS, or
DCD are available. Bit banging may be the only solution when dedicated communication hardware is not available.
Example
The following
C language
C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities o ...
code example transmits a byte of data on an
SPI bus via bit banging.
void send_8bit_serial_data(unsigned char data)
See also
*
*
*
*
*
*
*
* (IWM)
*
*
*
*
References
{{reflist, refs=
[{{cite book , title=Programming and customizing PICmicro microcontrollers , edition=2nd , author-first=Michael , author-last=Predko , publisher=]McGraw-Hill Professional
McGraw Hill is an American education science company that provides educational content, software, and services for students and educators across various levels—from K-12 to higher education and professional settings. They produce textbooks, ...
, date=2000 , isbn=978-0-07-136172-9 , page
10
��12 , url=https://archive.org/details/programmingcusto00pred_0, url-access=registration
[{{cite web , url=https://www.analog.com/en/resources/glossary/bit_banging.html, title=Analog Devices Glossary of Electrical Engineering (EE) Terms , access-date=22 September 2024]
External links
Efficient bit-banged SPI for 8051 microcontroller
Data transmission
Signal processing
Digital circuits
Embedded systems