In
computer engineering
Computer engineering (CoE or CpE) is a branch of electrical engineering and computer science that integrates several fields of computer science and electronic engineering required to develop computer hardware and software. Computer enginee ...
and
electrical engineering, bit banging is a "
term of art
Jargon 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 context is usually a partic ...
" for any method of
data transmission
Data transmission and data reception or, more broadly, data communication or digital communications is the transfer and reception of data in the form of a digital bitstream or a digitized analog signal transmitted over a point-to-point o ...
that employs software as a substitute for dedicated hardware to generate transmitted signals or process received signals. Software directly sets and
samples the states of
GPIOs (e.g., pins on a
microcontroller
A microcontroller (MCU for ''microcontroller unit'', often also MC, UC, or μC) is a small computer on a single VLSI integrated circuit (IC) chip. A microcontroller contains one or more CPUs ( processor cores) along with memory and programma ...
), and is responsible for meeting all timing requirements and protocol sequencing of the signals. In contrast to bit banging, dedicated hardware (e.g.,
UART,
SPI
SPI may refer to:
Organizations
* Indian Protection Service (''Serviço de Proteção ao Índio''), Brazil
* Shotmed Paper Industries, an Egyptian paper manufacturers
* Simulations Publications, Inc., a former US board game publisher
* Sony P ...
,
I²C
I2C (Inter-Integrated Circuit, ), alternatively known as I2C or IIC, is a synchronous, multi-controller/multi-target (master/slave), packet switched, single-ended, serial communication bus invented in 1982 by Philips Semiconductors. It is w ...
) satisfies these requirements and, if necessary, provides a
data buffer to relax software timing requirements. Bit banging can be implemented at very low cost, and is commonly used in some
embedded systems
An embedded system is a 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 ''embedded'' ...
.
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.
C code example
The following
C language code example transmits a byte of data on an
SPI
SPI may refer to:
Organizations
* Indian Protection Service (''Serviço de Proteção ao Índio''), Brazil
* Shotmed Paper Industries, an Egyptian paper manufacturers
* Simulations Publications, Inc., a former US board game publisher
* Sony P ...
bus.
// transmit byte serially, MSB first
void send_8bit_serial_data(unsigned char data)
Considerations
The question whether to deploy bit banging or not is a trade-off between load, performance and reliability on one hand, and the availability of a hardware alternative on the other. The software emulation process consumes more processing power than does supporting dedicated hardware. The microcontroller spends much of its time sending or receiving samples to and from the pins, at the expense of other tasks. The signal produced usually has 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 significa ...
or
glitches, especially if the processor is also executing other tasks while communicating. However, if the bit-banging software is
interrupt
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted ...
-driven by the signal, this may be of minor importance, especially if control signals such as
RTS, CTS, or
DCD are available. The implementation in software can be a solution when specific hardware support is not available or requires a more expensive microcontroller.
See also
*
Bit manipulation
*
Bit stream
A bitstream (or bit stream), also known as binary sequence, is a sequence of bits.
A bytestream is a sequence of bytes. Typically, each byte is an 8-bit quantity, and so the term octet stream is sometimes used interchangeably. An octet may ...
*
Bit twiddler (disambiguation) In computing, bit twiddler may refer to:
* A piece of source code that does ''bit twiddling'', which may mean:
** Doing bit manipulation;
** Interacting with computer hardware, especially when using a bit-banging technique;
** Reading or writing ...
*
Bit-serial architecture
In digital logic applications, bit-serial architectures send data one bit at a time, along a single wire, in contrast to bit-parallel word architectures, in which data values are sent all bits or a word at once along a group of wires.
All d ...
*
1-bit architecture
In computer architecture, 1-bit integers or other data units are those that are (1/8 octet) wide. Also, 1-bit central processing unit (CPU) and arithmetic logic unit (ALU) architectures are those that are based on registers of that size.
...
*
Fast loader
*
Integrated Woz Machine
The Integrated Woz Machine (or IWM for short) is a single-chip version of the floppy disk controller for the Apple II. It was also employed in Macintosh computers.
History
When developing a floppy drive for the Apple II, Apple Inc. co-foun ...
(IWM)
*
FTDI, a series of USB to serial converter chips also supporting a bit bang mode
*
2MGUI
2M is a DOS program by the Spanish programmer Ciriaco García de Celis. It enables higher than normal capacity formatting of floppy disks. It saw active development from 1993 to 1995. The last version, v3.0, was released on 6 March 1995. It was ...
(a DOS driver by Ciriaco García de Celis utilizing bit-banging to support non-standard ultra-high capacity floppy disk formats "bypassing" the normal floppy controller logic, a similar program for Amiga floppies is Vincent Joguin's Disk2FDI)
*
Virtual machine
In computing, a virtual machine (VM) is the virtualization/ emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized har ...
(VM) (implementing virtual device drivers emulating actual hardware controllers sometimes involves utilizing programming techniques similar to bit banging)
*
Software-defined radio
Software-defined radio (SDR) is a radio communication system where components that have been traditionally implemented in analog hardware (e.g. mixers, filters, amplifiers, modulators/ demodulators, detectors, etc.) are instead implemented b ...
(SDR)
*
Polling (computer science)
Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output (), and is also referred to as po ...
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 educational publishing company and one of the "big three" educational publishers that publishes educational content, software, and services for pre-K through postgraduate education. The company also publishes referenc ...
, date=2000 , isbn=978-0-07-136172-9 , page
10
��12 , url=https://archive.org/details/programmingcusto00pred_0, url-access=registration
External links
;Asynchronous serial (RS-232)
;I²C bus
;SPI bus
Efficient bit-banged SPI for 8051 microcontroller
Data transmission
Signal processing
Digital circuits
Embedded systems