4

Assuming I realize some communication protocol (e.g. SPI or I2C) just with GPIOs (no dedicated HW). In order to handle timing, I can either:

  1. set interrupt on the CLK edge
  2. set timer interrupt and test the DATA line periodically

Option 1 uses external interrupt (the CLK signal comes from the outer world), while option 2 does not rely on external signals (if CLK line disconnects from whatever reason, it still works - it doesn't depend on it)

Finally, the question: can both options 1 and 2 be referred to as "bit-banging", or just the second?

(as the term "banging" can be interpreted as "knock with constant pace". I hope my question is clear...)

Tar
  • 163
  • 3

3 Answers3

13

Both. Bit-Banging describes for me emulating a protocol just using non-specialized hardware modules (e.g. GPIOs).

Tom L.
  • 7,969
  • 1
  • 19
  • 34
  • 2
    +1 I'd even refer to using shift registers (the LPC43xx SGPIO) as bit-banging, as you have to program the signal waveforms as bits in the shift registers. And "bit-banging at 200 MHz" just sounds too cool to not use it :-). – starblue Nov 08 '13 at 14:18
8

I think the Wikipedia article on bit banging pretty much answers your question in the first sentence:

Bit banging is a technique for serial communications using software instead of dedicated hardware.

The timer and interrupt hardware are not dedicated hardware. They are general use hardware that can be adapted for many purposes. And it's really the software that you write in the interrupt service routine that is doing the work. So both can be considered bit banging.

The article further goes on to mention issues with using only a simple polling routine to bit bang. Polling takes time away from other tasks and in a resource constrained embedded system, this can be an issue. Depending on how high priority you make your polling interrupt, it itself can be interrupted and then either miss incoming data or cause the output signal to be of low quality.

embedded.kyle
  • 8,411
  • 2
  • 26
  • 44
1

Bit-banging is when a UART or USART hardware component or module is not available or not used.

It basically means that software needs to service each bit possibly through loop, counter compare or interrupt.

Using a shift register macro-cell or external component is not true bit-banging unless software is providing at least the clock or start/end conditions, if a hardware timer is driving a shift register you have created a crude ART (asynchronous receiver, transmitter) add some more VHDL code and it is a UART (but if you consider the VHDL to be code then it is bit-banging).

EDIT:
On deeper reflection I need to make further clarification. Bit-banging is different from what may be the other type by virtue of the fact that it is done a bit at a time rather than a byte (or word) at a time. This means that the software has to perform multiple communications operations corresponding to work done for each bit with possible additional overheads for start and stop bits or state changes depending on the format/protocol. It make the shift register the antithesis of bit-banging because it is the circuit component that will be able to clock out multiple bits unattended. An uncertain situation would be using a shift register to move the data but generating the clock edges in software. This would probably fall into Bit-banging still due to the fact that the software has to service the (clock of the) data movement on a bit-by-bit basis (even with the data shift register).

If you set up a ART, UART, USART, SPI, I2C etc peripheral and then send a byte (or word) and the data moves out (or in) without further software assistance that would NOT be Bit-banging.

KalleMP
  • 4,039
  • 1
  • 14
  • 32
  • 1
    Bit-banging is not limited to UART/USART; it can be used for any serial protocol (e.g. I2C, SPI etc.) where GPIOs are used instead of dedicated protocol-specific hardware. – tcrosley Sep 08 '16 at 00:56
  • 1
    I would use the term "bit banging" to refer to a situation where every bit is processed individually by software at either the physical or logical data level (e.g. using a UART for Dallas/Maxim one-wire protocol by sending a 0xFF for each short pulse and 0x00 for each long pulse would be bit-banging even though it's using a UART, because each *logical* bit would be processed individually) – supercat Sep 12 '16 at 18:27