Hi. First time poster - so please don't shoot me down too violently!
I was looking through the SoftwareSerial.cpp code. I noticed the following:
void SoftwareSerial::print(uint8_t b)
{
if (_baudRate == 0)
return;
int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); // a digitalWrite is about 50 cycles
byte mask;
digitalWrite(_transmitPin, LOW);
delayMicroseconds(bitDelay);
for (mask = 0x01; mask; mask <<= 1) {
if (b & mask){ // choose bit
digitalWrite(_transmitPin,HIGH); // send 1
}
else{
digitalWrite(_transmitPin,LOW); // send 1
}
delayMicroseconds(bitDelay);
}
digitalWrite(_transmitPin, HIGH);
delayMicroseconds(bitDelay);
}
My question is, wouldn't this save a few cycles ? I'm finding the whole thing a bit slow, and am looking for some speed-ups.
void SoftwareSerial::print(uint8_t b)
{
if (_baudRate == 0)
return;
int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); // a digitalWrite is about 50 cycles
byte mask;
digitalWrite(_transmitPin, LOW);
delayMicroseconds(bitDelay);
for (mask = 0x01; mask; mask <<= 1) {
digitalWrite(_transmitPin,(b & mask));
delayMicroseconds(bitDelay);
}
digitalWrite(_transmitPin, HIGH);
delayMicroseconds(bitDelay);
}
Regards,
Marv