# bit_bang_uart.c File Reference

bit-bang UART implementation More...

`#include "bit_bang_uart.h"`
`#include "msp430x24x.h"`

## Defines
#define | MDB 1
#define | BIT_BANG_TX_PORT P6OUT
#define | BIT_BANG_TX_BIT BIT7
#define | BIT_BANG_RX_PORT P2IN
#define | BIT_BANG_RX_BIT BIT5
#define | DISABLE_BIT_BANG_RX_INTERRUPT() (P2IE &= ~BIT5)
#define | ENABLE_BIT_BANG_RX_INTERRUPT() (P2IE |= BIT5)
#define | BIT_LENGTH_9600 160
#define | HALF_BIT_LENGTH_9600 76
#define | BIT_LENGTH_19200 75
#define | HALF_BIT_LENGTH_19200 27
#define | OUTPUT_1() (BIT_BANG_TX_PORT |= BIT_BANG_TX_BIT)
#define | OUTPUT_0() (BIT_BANG_TX_PORT &= ~BIT_BANG_TX_BIT)
#define | NUMBER_OF_DATA_BITS 8
#define | TOGGLE_DEBUG_PIN() (P4OUT ^= BIT5)
## Functions
void | delayFullBit ()
void | delayHalfBit ()
void | bitBangOutput (unsigned char outputByte)
char | bitBangInput ()

## Detailed Description

bit-bang UART implementation

This file implements a simple software defined Universal Asynchronous Receiver/Transmitter (UART). For simplicity and portability, timing is done using delay loops. Depending on hardware resources, you may want to use a timer instead.

Baud rate is 19200 in the format 8-N-1: 8 data bits, no parity, 1 stop bit. Line is normally high.

The defines will need to be modified if changing hardware implementation.

Note:
  if changing hardware implementation, first verify with an oscilloscope or similar that the timing is correct. For example, bit width in 9600 bps one bit width is 104.2uSec, at 19,200 it is 52.08uSec, and at 38,400 it is 26.041uSec. Best way to do this is output 'U' and measure the bit widths.

Rev
  365

Author
  dsmith

Date
  2010-03-24 16:57:31 -0700 (Wed, 24 Mar 2010)

URL
  http://dsmith@ns.svnrepository.com/svn/hardware/fw/ZNP%20Examples/bit_bang_uart.c

## Function Documentation

char bitBangInput | ( |  | ) |

Blocking UART receiver. Called by BIT_BANG_RX_PORT Interrupt Service Routine upon detection of start bit (high to low transition). BIT_BANG_RX_BIT should be configured as high-low edge triggered interrupt. Receives a byte and then processes it.

Note:
  BIT_BANG_RX_PORT, BIT_BANG_RX_BIT, DISABLE_BIT_BANG_RX_INTERRUPT(), and ENABLE_BIT_BANG_RX_INTERRUPT() must be defined. Modify accordingly for other hardware.

Precondition:
  Oscillator configured for 8MHz
  A high-to-low transition has occurred on BIT_BANG_RX_BIT

Returns:
  the byte received

void bitBangOutput | ( | unsigned char | outputByte | ) |

Transmits one byte out the specified pin

## To Send a Byte

- Line is nominally at '1' (high)
- 1 Start bit = '0'
- Data, MSB first, LSB last. '1' = line high, '0' = line low
- 1 Stop bit = '1' (idle, or high)
  Note:
    BIT_BANG_RX_PORT, BIT_BANG_RX_BIT, DISABLE_BIT_BANG_RX_INTERRUPT(), and ENABLE_BIT_BANG_RX_INTERRUPT() must be defined. Modify accordingly for other hardware.
  Precondition:
    Oscillator configured for 8MHz
    port/bit configured for logic output.
    bit is high (logic '1')
  Parameters:

    | byte | the byte to output

void delayFullBit | ( |  | ) |

Simple delay for bit width. Used in transmit and receive.

void delayHalfBit | ( |  | ) |

Simple delay for 1/2 of bit width. Used in receive.

All Files Functions Variables