Skip to content

HardwareSerial::setPins does not unset previous pin #8607

Closed
@LupinIII

Description

@LupinIII

Board

NodeMCU ESP-C3-13

Device Description

similar to ESP32-C3-DevKitC-02/ESP32-C3-DevKitM-01

Hardware Configuration

No

Version

v2.0.11

IDE Name

PlatformIO

Operating System

Windows 10

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

460800

Description

When using HardwareSerial::setPins (e.g. "Serial.setPins(2,3,-1,-1)") the TX pin previously set for that port does not get "unset". In the example below all the pins will output serial data at the same time. When checking on the logic analyzer, you can see that at startup only one pin outputs data (the "0b10101010" pattern). One after another a pin starts outputting data. After the for loop has completed, all pins output the same serial data. I also confirmed that when connecting an USB-TTL-converter to any of those pins, the data can be read.

This is not specific to "Serial", but also happens for "Serial1". And it does not depend on specific pins either.

I could not reproduce the same behavior for RX.

Sketch

#include <Arduino.h>

#define SERIAL0_BAUD 19200
#define SERIAL0_PARAM SERIAL_8N1
#define SERIAL0_RXPIN 4
#define SERIAL0_TXPIN 0

static const uint8_t pins[] = {2,9,3,10,18,19,20,21}; // pins to set TX to (chosen for no other reason than that they are on one side of the dev board and the logic analyzer is easier to connect to)

void setup() {
	Serial.begin(SERIAL0_BAUD, SERIAL0_PARAM, SERIAL0_RXPIN, SERIAL0_TXPIN);
}

void loop() {
	for (auto pin: pins) {
		Serial.setPins(-1, pin, -1, -1); // only change TX pin
		Serial.write(0b10101010);
		delay(1); // give UART time to send the byte
	}
}

Debug Message

I don't have a cmsis-dap device, which PlatformIO expects me to have when trying to debug.

Other Steps to Reproduce

As a workaround (although a lot slower) calling Serial.end() followed by a Serial.begin() with the new pin works as expected (the data output switched from pin to pin).

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions