2 Software serial multple serial test
4 Receives from the hardware serial, sends to software serial.
5 Receives from software serial, sends to hardware serial.
8 * RX is digital pin 10 (connect to TX of other device)
9 * TX is digital pin 11 (connect to RX of other device)
12 Not all pins on the Mega and Mega 2560 support change interrupts,
13 so only the following can be used for RX:
14 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
16 Not all pins on the Leonardo support change interrupts,
17 so only the following can be used for RX:
18 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
20 created back in the mists of time
23 based on Mikal Hart's example
25 This example code is in the public domain.
28 #include <SoftwareSerial.h>
30 //SoftwareSerial mySerial(10, 11); // RX, TX
31 int ledPin = 13; // LED connected to digital pin 13
35 void sendChar( uint8_t toSend) ;
39 // Open serial communications and wait for port to open:
41 Serial.println("Serial setup");
43 // set the data rate for the SoftwareSerial port used is read mode
44 // mySerial.begin(38400);
45 // mySerial.println("Hello, world?");
47 pinMode(ledPin, OUTPUT); // sets the digital pin as output
52 void loop() // run over and over
58 if ( ad > 15 ) ad = 0 ;
61 if (mySerial.available()) {
64 } while (mySerial.available()) ;
65 digitalWrite(ledPin, HIGH); // sets the LED on
68 digitalWrite(ledPin, LOW); // sets the LED off
74 // specific software is use to simule multiplex RX
75 // pin 10 is used here (could be anay other
76 // pin 10 is normally configured as input with pull up enabled, so level is normally high
77 // When a byte must be sent, a change is require to force output mode with 0 e.g for the startbit
80 //arduino pin 10 is on avr pin 14 = PB2
82 DDRB &= ~( 1 << DDB2 ) ; // PIN is input.
83 PORTB &= ~( 1 << PORTB2 ) ; // PIN is tri-stated.
86 void sendChar( uint8_t toSend) {
87 // baud rate is 38 400 => 1000000 / 38400 = 26 usec
88 DDRB |= ( 1 << DDB2 ) ; // PIN is output.
90 delayMicroseconds(26);
91 for (uint8_t i= 0 ; i<8 ; i++) {
92 if( toSend & 0x01 ) { // If the LSB of the TX buffer is 1:
93 DDRB &= ~( 1 << DDB2 ) ; // PIN is input = level is high
94 } else { // Otherwise:
95 DDRB |= ( 1 << DDB2 ) ; // PIN is output = level is low
97 toSend = toSend >> 1 ; // Bitshift the TX buffer and
98 delayMicroseconds(26);
100 DDRB &= ~( 1 << DDB2 ) ; // PIN is input = level is high
101 delayMicroseconds(26);