Hi,
I am using SoftSerial on a 8Mhz board and I am trying to communicate at 1200 baud (that's all the transmitter I own allows). I am currently only sending data in a loop.
#include <TinyPinChange.h>
#include <SoftSerial.h>
.
#define DEBUG_TX_RX_PIN 0 //Adjust here your Tx/Rx debug pin
.
SoftSerial MyDbgSerial(DEBUG_TX_RX_PIN, DEBUG_TX_RX_PIN, true); //true allows to connect to a regular RS232 without RS232 line driver
.
void setup()
{
MyDbgSerial.begin(1200); //After MyDbgSerial.begin(), the serial port is in rxMode by default
MyDbgSerial.txMode(); //Before sending a message, switch to txMode
MyDbgSerial.println(F("\nDebug enabled"));
MyDbgSerial.rxMode(); //switch to rxMode to be ready to receive some commands
}
.
void loop()
{
delay(500);
MyDbgSerial.txMode();
MyDbgSerial.print("Hello: ");
MyDbgSerial.rxMode();
if(MyDbgSerial.available())
{
MyDbgSerial.read();
}
}
Afther running this code (Against the official arduino) I figured out the transmit times where far of so
I used a logic analyzer to tweak the table in DigisparkSoftSerial/SoftSerial.cpp to make it all work
diff --git a/libraries/DigisparkSoftSerial/SoftSerial.cpp b/libraries/DigisparkSoftSerial/SoftSerial.cpp
index 03b3b33..45ffbc0 100755
--- a/libraries/DigisparkSoftSerial/SoftSerial.cpp
+++ b/libraries/DigisparkSoftSerial/SoftSerial.cpp
@@ -121,8 +121,8 @@ static const DELAY_TABLE table[] PROGMEM =
{ 14400, 30, 75, 75, 72, },
{ 9600, 50, 114, 114, 112, },
{ 4800, 110, 233, 233, 230, },
- { 2400, 229, 472, 472, 469, },
- { 1200, 467, 948, 948, 945, },
+ { 2400, 229, 472, 472, 600, },
+ { 1200, 467, 948, 948, 1277, },
{ 300, 1895, 3805, 3805, 3802, },
};
the bit time with that changes is very close to 1000/1200 = 0.8333 ms.
I am expecting this is a bug in the SoftSerial.cpp code but I would like to know for sure. I also found the 2400 baud to be far of. I am willing to update the table if needed( and I did not change things for receiving yet).