Skip to content

Fix Serial pin reassignment on speed change; document LISTEN_ONLY vs emulation wiring#3

Open
jenogc wants to merge 2 commits intoLexOptical:masterfrom
jenogc:fix/serial-pin-reassignment-on-speed-change
Open

Fix Serial pin reassignment on speed change; document LISTEN_ONLY vs emulation wiring#3
jenogc wants to merge 2 commits intoLexOptical:masterfrom
jenogc:fix/serial-pin-reassignment-on-speed-change

Conversation

@jenogc
Copy link
Copy Markdown

@jenogc jenogc commented Mar 11, 2026

Fixes #1

Problem

Two related issues stemming from the pin-assignment conflict described in #1:

  1. setLowspeedMode() / setHighspeedMode() called Serial1.begin() without re-applying setRX/setTX, which could revert to hardware-default pins on a speed change. In LISTEN_ONLY mode the TX line should be routed to the unused PIN5, but without explicit pin re-assignment it would fall back to PIN1 — the same pin that the emulation mode uses for the lens→body data line.

  2. The circuit diagram and README gave no indication that the wiring differs between modes, leaving users to discover the PIN0/PIN1 discrepancy by reading the code.

Changes

E-Mount.ino

  • In both setLowspeedMode() and setHighspeedMode(), explicitly call Serial1.setRX(0), Serial1.setTX(LISTEN_ONLY ? 5 : 1), and Serial2.setRX(9) before each Serial.begin() — mirroring what setup() already does.

README.md

  • Added a note under the circuit diagram explaining that the diagram covers LISTEN_ONLY wiring only.
  • Added a pin-assignment table showing the correct connections for both LISTEN_ONLY and emulation modes.

In setLowspeedMode() and setHighspeedMode(), calling Serial1.begin()
without first calling setRX/setTX could revert to hardware-default pins,
causing PIN1 to be used as TX even in LISTEN_ONLY mode (where TX should
be routed to the unused PIN5).

Fix: explicitly call setRX/setTX before each Serial.begin() call in
both speed-change helpers, mirroring the setup() logic.

Also update README to clarify that the circuit diagram covers LISTEN_ONLY
wiring only, and that non-LISTEN_ONLY (emulation) mode additionally
requires PIN1 connected to the LENS7 data line.

Fixes LexOptical#1
@Bostwickenator
Copy link
Copy Markdown
Contributor

@claude I'd also like to pull the pin numbers out into named constants instead of adding more instances of 5 and 9 all over. Can you do that in this PR please

Add PIN_SERIAL1_RX (0), PIN_SERIAL1_TX_ACTIVE (1), PIN_SERIAL1_TX_LISTEN (5),
and PIN_SERIAL2_RX (9) to Constants.h, replacing all raw literals in E-Mount.ino.
The three existing control-signal constants (PIN_LENS_CS_BODY, PIN_BODY_CS_LENS,
PIN_BODY_VD_LENS) were already named; serial pins now match that convention.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jenogc
Copy link
Copy Markdown
Author

jenogc commented Mar 12, 2026

@Bostwickenator latest commit addresses your comment above. Thanks for putting this project out there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mismatch between code and circuitdiagram?

3 participants