Software serial, for when you are out of serial pins

Dependents:   BufferedSoftSerial neurGAI_Seeed_BLUETOOTH LPC-SD-35 ESP-WROOM-02_test ... more

Committer:
Sissors
Date:
Sat Apr 26 16:21:42 2014 +0000
Revision:
2:9e01a38606b4
Parent:
1:f8b4b764ace7
Child:
5:acfd0329f648
TX optimised to handle 19200 on LPC1768

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:8edaa7abe724 1 #include "SoftSerial.h"
Sissors 0:8edaa7abe724 2
Sissors 0:8edaa7abe724 3 SoftSerial::SoftSerial(PinName TX, PinName RX) {
Sissors 0:8edaa7abe724 4 tx_en = rx_en = false;
Sissors 0:8edaa7abe724 5 if (TX != NC) {
Sissors 0:8edaa7abe724 6 tx = new DigitalOut(TX);
Sissors 0:8edaa7abe724 7 tx_en = true;
Sissors 0:8edaa7abe724 8 tx->write(1);
Sissors 0:8edaa7abe724 9 tx_bit = -1;
Sissors 0:8edaa7abe724 10 }
Sissors 0:8edaa7abe724 11 if (RX != NC) {
Sissors 0:8edaa7abe724 12 rx = new InterruptIn(RX);
Sissors 0:8edaa7abe724 13 rx_en = true;
Sissors 1:f8b4b764ace7 14 out_valid = false;
Sissors 0:8edaa7abe724 15 rx->fall(this, &SoftSerial::rx_gpio_irq_handler);
Sissors 0:8edaa7abe724 16 }
Sissors 0:8edaa7abe724 17
Sissors 0:8edaa7abe724 18 baud(9600);
Sissors 0:8edaa7abe724 19 format();
Sissors 0:8edaa7abe724 20 }
Sissors 0:8edaa7abe724 21
Sissors 0:8edaa7abe724 22 void SoftSerial::baud(int baudrate) {
Sissors 0:8edaa7abe724 23 bit_period = 1000000 / baudrate;
Sissors 0:8edaa7abe724 24 }
Sissors 0:8edaa7abe724 25
Sissors 0:8edaa7abe724 26 void SoftSerial::format(int bits, Parity parity, int stop_bits) {
Sissors 0:8edaa7abe724 27 _bits = bits;
Sissors 0:8edaa7abe724 28 _parity = parity;
Sissors 0:8edaa7abe724 29 _stop_bits = stop_bits;
Sissors 2:9e01a38606b4 30 _total_bits = 1 + _bits + _stop_bits + (bool)_parity;
Sissors 0:8edaa7abe724 31 }