PaulStoffregen / AltSoftSerial

Software emulated serial using hardware timers for improved compatibility
http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
338 stars 132 forks source link

Sending two inverting TX signals on two digital outputs at the same time #40

Open fdobrota opened 7 years ago

fdobrota commented 7 years ago

Hi, please is possible to use AltSoftSerial for sending TX+ and TX- signal on two Arduino digital outputs at the same time ? The same serial data, but inverted logical level on second digital output, so it wouldn't necessary to use any hardware invertor for it.

PaulStoffregen commented 7 years ago

The answer is: it depends.

First, this isn't possible unless you modify the AltSoftSerial code. AltSoftSerial simply doesn't offer this feature. But it is open source, so if you have the time and skill to edit the code, perhaps you can do it. Maybe you'll even share for others who might want it?

This message is the one and only thing I will do to help. If you really want this, you have dig into the code and do it yourself.

Second, this can only work on chips where the timer has at least 3 compare channels. ATMEGA328P (used on Arduino Uno & Nano) have only 2 compare registers. One is used for the output signal and another is used for a timeout, so you must have at least a 3rd compare to generate another signal.

The basic idea would be to configure the 3rd compare channel to generate an output signal. If the hardware supports opposite polarity (depends on which chip you use), then the code might be as simple as merely writing the same data to the 3rd compare register. Maybe? There could be other details. It really depends on the timer compare unit details for whatever chip you're using.