I made a small tweak to the HardwareSerial library (IDE 1.0.1) to have the ability to use only RX, only TX, or both RX and TX (normal operation). The modifications are very simple and easy to use. I've shown the modifications below. Make a copy of Arduino.h, HardwareSerial.h and HardwareSerial.cpp located in folder \arduino-1.0.1\hardware\arduino\cores\arduino\ and save them to a folder somewhere so if you screw up you can copy the old files back to the original folder.
Make the changes where indicated to the files below.
// Place the three statements below somewhere around line 20
// with the other #define's that are listed there.
#define RX_TX 0
#define RX_ONLY 1
#define TX_ONLY 2
// Change the declaration below (at line 52)
void begin(unsigned long);
// To this
void begin(unsigned long, uint8_t mode = RX_TX);
// Change the definition below (at line 294)
void HardwareSerial::begin(unsigned long baud)
// To this
void HardwareSerial::begin(unsigned long baud, uint8_t mode)
// Located at the end of the same function (above)
// Replace the statements below (at lines 328, 329, 330)
// With these
If you want keyword highlighting for the new constants, you can add a few lines to \arduino-1.0.1\lib\keywords.txt file, though it is not neccesary.
// Right after the line below (at line 1)
# LITERAL1 specifies constants
// Place these three lines (Use tabs here, NOT spaces)
RX_ONLY LITERAL1 Serial_begin
TX_ONLY LITERAL1 Serial_begin
To use the new changes, it's a simple addition to Serial.begin().
// Functions the same as it always has
// The receive pin (RXDn) and transmit pin (TXDn) are both controlled by HardwareSerial
// Functions the same as above
// Only the receive pin (RXDn) is controlled by HardwareSerial
// The transmit pin (TXDn) is free to use as digital I/O
// Only the transmit pin (TXDn) is controlled by HardwareSerial
// The receive pin (RXDn) is free to use as digital I/O
I've tested this succesfully using IDE 1.0.1 and the Mega1280/2560 on Serial ports 1, 2 and 3. I think I need to connect two arduinos to check port 0. If someone could test this out and let me know, maybe we could get this in the next build.
Thanks for your time,