Skip to content

Serial.end() not reattaching pin to GPIO matrix #3205

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

Closed
luketanti opened this issue Sep 13, 2019 · 16 comments
Closed

Serial.end() not reattaching pin to GPIO matrix #3205

luketanti opened this issue Sep 13, 2019 · 16 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@luketanti
Copy link

luketanti commented Sep 13, 2019

After trying to switch back two UART pins to GPIO by using the Serial.end() function, the pins do not respond to digitalWrite commands.

I have found out that by using gpio_matrix_out(gpio_number, SIG_GPIO_OUT_IDX, false, false); I am able to use the pin again after ending the Serial.

@stickbreaker
Copy link
Contributor

@luketanti after using Serial.end() did you do a pinMode(pin,OUTPUT) before doing a digitalWrite(pin,value)?

Chuck.

@luketanti
Copy link
Author

@luketanti after using Serial.end() did you do a pinMode(pin,OUTPUT) before doing a digitalWrite(pin,value)?

Chuck.

Yes, offcourse.

Here are two snippets. The first one is when the issue occurs and the second is how I managed to get the pin to respond to digitalWrite commands.

  Serial2.end();
  pinMode(K_TX, OUTPUT);
  pinMode(K_RX, INPUT);
  digitalWrite(K_TX, HIGH);
  delay(298);
  digitalWrite(K_TX, LOW);
  delay(23);
  digitalWrite(K_TX, HIGH);
  delay(23);

  Serial2.begin(10417, SERIAL_8N1, K_RX, K_TX);  // K-LINE
  Serial2.end();
  gpio_matrix_out(K_TX, SIG_GPIO_OUT_IDX, false, false);
  pinMode(K_TX, OUTPUT);
  pinMode(K_RX, INPUT);
  digitalWrite(K_TX, HIGH);
  delay(298);
  digitalWrite(K_TX, LOW);
  delay(23);
  digitalWrite(K_TX, HIGH);
  delay(23);

  Serial2.begin(10417, SERIAL_8N1, K_RX, K_TX);  // K-LINE

@atanisoft
Copy link
Collaborator

Did you try gpio_reset(K_TX); instead of gpio_matrix_out?

@luketanti
Copy link
Author

I have tried to compile with gpio_reset(K_TX); but it failed.

exit status 1
'gpio_reset' was not declared in this scope

Shouldn't Serial.end() automatically release the pins allocated to other use?

@atanisoft
Copy link
Collaborator

Sorry that should have been gpio_reset_pin. And yes I'd think that Serial.end() should release the pin to normal/default state. I believe there was an older issue for the same.

@luketanti
Copy link
Author

Yes, I can confirm that it also works.

gpio_reset_pin(GPIO_NUM_17); in my case.

Can this line be added to the UART HAL?
And in future Arduino core updates this would be included?

@atanisoft
Copy link
Collaborator

@luketanti send in a PR that does this for both RX and TX in the esp32-hal-uart.c file in the uartEnd() method and I'm sure @me-no-dev will consider it.

@me-no-dev
Copy link
Member

huh? this is rather really strange. this is already called in uartEnd() when the pins are detached from the matrix (gpio_matrix_out(gpio_number, SIG_GPIO_OUT_IDX, false, false);)

@stickbreaker
Copy link
Contributor

@me-no-dev my 2 cents: The only difference I see between I2C(working) and UART de-init is a call to pinMode(pin,INPUT | PULLUP);

Has anyone other than the OP validated this behavior?

That is why I asked my silly question above.

Chuck.

@stickbreaker
Copy link
Contributor

stickbreaker commented Sep 14, 2019

@luketanti do you call Serial.flush(); before you call Serial.end();?
Could it be a case where the UART is still in use (ISR active)?

Chuck.

@bertmelis
Copy link
Contributor

flush blocks untill uart's FSM is idle.

@stickbreaker
Copy link
Contributor

@bertmelis yep, that is its purpose. I believe reconfiguring UART should not happen until it is idle.

@stale
Copy link

stale bot commented Nov 14, 2019

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Nov 14, 2019
@stale
Copy link

stale bot commented Nov 28, 2019

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Nov 28, 2019
@WayneKeenan
Copy link

This is still an issue on Pin16 (U2RX) on ESP-CAM using Arduino 1.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

6 participants