Software UART program using Infra-Red LED and IR-Detector
Dependents: TestVirtualisation Bf_SoftSerial_IR
SoftSerial.cpp@1:f8b4b764ace7, 2014-04-26 (annotated)
- Committer:
- Sissors
- Date:
- Sat Apr 26 15:13:01 2014 +0000
- Revision:
- 1:f8b4b764ace7
- Parent:
- 0:8edaa7abe724
- Child:
- 2:9e01a38606b4
RX basic functional
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:8edaa7abe724 | 30 | } |