fix(SoftwareSerial): correct TX to RX switch when using half-duplex #1771
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When working with single-pin half-duplex SoftwareSerial, I noticed that after the call to
listen()receiving data is not possible until data is written. In factsetRXTX(true)is only called withinsend(), which in turn is only called as long asactive_outis set (i.e. ongoing transmission). Since at the beginning oflisten()completion of any ongoing transmissions is awaited, the SoftwareSerial will not actively listen before another transmission is completed.This PR fixes/implements the following bugs/features
This occurs if the communication is not initiated by the STM32. Otherwise, one would simply call
listen()and then send whatever will trigger the other side to respond.In my case, I wanted to use a second line to indicate the direction of communication (which however can not be used as a second line for full-duplex). I must admit that this is probably a very rare case, and the fix I suggest will in fact change the current behavior of calling
listen()before sending data. However it took me a few hours to debug this and I thought I should at least mention this finding in case someone else stumbles upon it.