I am rather new to Digispark, but having some programming experience.
I am trying to modify TwoPortReceive.ino example supplied with DigisparkSoftSerial library. The example is partially inappropriate for Digispark as it uses hardware Serial which is not available on Digispark Attiny85.
My code is like this (introductory comments skipped):
#include <SoftSerial.h> /* Allows Pin Change Interrupt Vector Sharing */
#include <TinyPinChange.h> /* Ne pas oublier d'inclure la librairie <TinyPinChange> qui est utilisee par la librairie <RcSeq> */
#define BAUD (38400)
SoftSerial serialOne(0, 1); // RX, TX
SoftSerial serialTwo(2, 3); // RX, TX
void setup() {
// set the data rate for the SoftSerial port
serialOne.begin(BAUD);
serialTwo.begin(BAUD);
delay(3000);
serialOne.println(F("\f\nserialOne\n****************"));
serialTwo.println(F("\f\nserialTwo\n****************"));
}
uint16_t tstamp = 0;
void loop() {
const int wait = 1;
uint16_t now_sec = millis() / 1000;
serialOne.listen();
delay(wait);
while (serialOne.available()) {
char c = serialOne.read();
serialOne.write(c);
tstamp = now_sec;
}
serialTwo.listen();
delay(wait);
while (serialTwo.available()) {
char c = serialTwo.read();
serialTwo.write(c);
tstamp = now_sec;
}
if ((now_sec-tstamp) >= 10) {
tstamp = now_sec;
serialOne.println(F("serialOne waiting ..."));
serialTwo.println(F("serialTwo waiting ..."));
}
}
The code compiles and uploads without any problems but inputs from any of the connected serial devices are randomly read fine or ignored. Each serial port is connected to different COMs served by PuTTy on Windows 7.
The problem is independent of the selected BAUD rate.
When one of the listen() statements is commented out, the particular SoftSerial port is served properly.
My guess is that the ISR for reading from serial ports are not working properly.
Am I missing something? Any hint is appreciated.