Bit-banging
Encyclopedia
Bit banging is a technique for serial communications
Serial communications
In telecommunication and computer science, serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels...

 using software instead of dedicated hardware. Software directly sets and samples
Sampling (signal processing)
In signal processing, sampling is the reduction of a continuous signal to a discrete signal. A common example is the conversion of a sound wave to a sequence of samples ....

 the state of pins on the microcontroller
Microcontroller
A microcontroller is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM...

, and is responsible for all parameters of the signal: timing, levels, synchronization, etc. In contrast to bit banging, dedicated hardware (such as a modem
Modem
A modem is a device that modulates an analog carrier signal to encode digital information, and also demodulates such a carrier signal to decode the transmitted information. The goal is to produce a signal that can be transmitted easily and decoded to reproduce the original digital data...

, UART, or shift register
Shift register
In digital circuits, a shift register is a cascade of flip flops, sharing the same clock, which has the output of any one but the last flip-flop connected to the "data" input of the next one in the chain, resulting in a circuit that shifts by one position the one-dimensional "bit array" stored in...

) handles these parameters and provides a (buffered) data interface in other systems, so software is not required to perform signal demodulation. Bit banging can be implemented at very low cost, and is used in, for example, embedded systems.

Although it is often considered to be something of a hack, bit banging does allow the same device to use different protocols with minimal or no hardware changes required.

There are some problems with bit banging. The software emulation process consumes more processing power than does supporting dedicated hardware. The microcontroller spends much of its time reading or sending samples to and from the pin, at the expense of other tasks. The signal produced normally has more jitter
Jitter
Jitter is the undesired deviation from true periodicity of an assumed periodic signal in electronics and telecommunications, often in relation to a reference clock source. Jitter may be observed in characteristics such as the frequency of successive pulses, the signal amplitude, or phase of...

 or glitch
Glitch
A glitch is a short-lived fault in a system. It is often used to describe a transient fault that corrects itself, and is therefore difficult to troubleshoot...

es, especially if the processor is also executing other tasks while communicating. However, if the bit-banging software is interrupt
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....

-driven by the signal, this may be of minor importance.

C code example


// transmit byte serially, MSB first
void send_8bit_serial_data(unsigned char data)
{
int i;

// select device
output_high(SD_CS);

// send bits 7..0
for (i = 0; i < 8; i++)
{
// consider leftmost bit
// set line high if bit is 1, low if bit is 0
if (data & 0x80)
output_high(SD_DI);
else
output_low(SD_DI);

// pulse clock to indicate that bit value should be read
output_low(SD_CLK);
output_high(SD_CLK);

// shift byte left so next bit will be leftmost
data <<= 1;
}

// deselect device
output_low(SD_CS);
}

External links

Asynchronous Serial (RS-232)

I2C Bus

SPI Bus
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK