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 14:46:03 2014 +0000
Revision:
0:8edaa7abe724
Child:
1:f8b4b764ace7
TX basic finished

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 0:8edaa7abe724 14 rx->fall(this, &SoftSerial::rx_gpio_irq_handler);
Sissors 0:8edaa7abe724 15 }
Sissors 0:8edaa7abe724 16
Sissors 0:8edaa7abe724 17 baud(9600);
Sissors 0:8edaa7abe724 18 format();
Sissors 0:8edaa7abe724 19 }
Sissors 0:8edaa7abe724 20
Sissors 0:8edaa7abe724 21 void SoftSerial::baud(int baudrate) {
Sissors 0:8edaa7abe724 22 bit_period = 1000000 / baudrate;
Sissors 0:8edaa7abe724 23 }
Sissors 0:8edaa7abe724 24
Sissors 0:8edaa7abe724 25 void SoftSerial::format(int bits, Parity parity, int stop_bits) {
Sissors 0:8edaa7abe724 26 _bits = bits;
Sissors 0:8edaa7abe724 27 _parity = parity;
Sissors 0:8edaa7abe724 28 _stop_bits = stop_bits;
Sissors 0:8edaa7abe724 29 }