Skip to content

Fix single-pin half-duplex in SoftwareSerial::send #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2019

Conversation

sjasonsmith
Copy link
Contributor

@sjasonsmith sjasonsmith commented Nov 2, 2019

Summary

When SoftwareSerial was adapted from the LPC1768 version, SoftwareSerial::send was altered in a way that prevents single-pin half-duplex communication from working properly.

This change reverts to the behavior seen in other repositories using variations of this code.

This PR fixes/implements the following bugs/features

  • Fixes one-wire half-duplex communication
  • No intentional breaking changes

This issue was discovered while testing a Marlin pull request which is adapting Marlin to work with STM32 5.7. During testing I found that one-pin communication with TMC stepper drivers did not work properly, although it did when using similar SoftwareSerial code from other sources.

The image below shows the same read command being sent to a TMC2208 stepper driver, both before and after the change in this PR. (Doesn't scale well, click to zoom)
SWSerial_Send_Compare

Validation

I have validated that I can now communicate properly with TMC stepper drivers using one-wire connections inside Marlin.

@sjasonsmith
Copy link
Contributor Author

sjasonsmith commented Nov 2, 2019

Tagging @ABOSTM. Perhaps they have insight into why these changes were originally made when porting SoftwareSerial to STM32.

@fpistm fpistm requested a review from ABOSTM November 2, 2019 06:00
@fpistm fpistm added the fix 🩹 Bug fix label Nov 2, 2019
@fpistm fpistm added this to the 1.8.0 milestone Nov 2, 2019
@sjasonsmith
Copy link
Contributor Author

I will modify my board this morning so that I can test when using two serial pins, to make sure I didn't break that.

@sjasonsmith
Copy link
Contributor Author

I will modify my board this morning so that I can test when using two serial pins, to make sure I didn't break that.

I just verified that I can also communicate with my TMC2208 stepper driver using two pins from Marlin.

@sjasonsmith
Copy link
Contributor Author

I ran into another issue during testing involving half-duplex.

The listen() called at the end of begin() causes SoftwareSerial to switch to RX as soon as a write finishes. This is true even if there is no read intended.

This problem can be sporadic, and also only impacts the SoftwareSerial instance which most recently ran begin().

This can cause communications issues for some hardware which is counting on the TX pin keeping the wire at the proper high state between transfers.

An example hardware combination is a BigTreeTech SKR Pro with their BTT 2208 modules.
This combination can read incorrect values, which is resolved by this change.

Before eliminating listen() call for half-duplex:
image

After:
image

Copy link
Contributor

@ABOSTM ABOSTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@fpistm
Copy link
Member

fpistm commented Nov 6, 2019

Thanks @ABOSTM

@fpistm fpistm merged commit db1b90f into stm32duino:master Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 🩹 Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants