RX / TX pin modes after Serial.end() (ATmega328P)

Hello,

I was wondering what wiill be the pin mode of RX / TX pins (PD0 / PD1) after Serial.end() is called? Are they going to be inputs or outputs?

I only found that the function clears the UART related interrupt and enable bits.

void HardwareSerial::end()
{
  // wait for transmission of outgoing data
  flush();

  cbi(*_ucsrb, RXEN0);
  cbi(*_ucsrb, TXEN0);
  cbi(*_ucsrb, RXCIE0);
  cbi(*_ucsrb, UDRIE0);
  
  // clear any received data
  _rx_buffer_head = _rx_buffer_tail;
}

Thanks in advance.

It sounds like you are planning to use pins 0 and 1 for something after using them for Serial. If so, what, else what does it matter what mode they are in and if it does then you could always use pinMode() in the sketch

More details of the problem that you are trying to solve would help to provide an answer

I turn off the supply voltage to the GSM module (using a high-side switch) after the necessary communications are complete. However, in this powered-off state, I measured an unusual voltage (~0.4V) on the uC RX pin (which should be 0V).

I think I’ve just figured out why this is happening while I was preparing an image for this post.

The voltage is likely being coupled back from the uC TX pin through the level-shift pull-up connection, which is also disconnected from VBAT in this powered-off state. Since the voltage is being divided, I assume some current is also flowing (unfortunately, my multimeter capable of measuring current is broken).

Is it possible that this is what's happening?

They are in the state they were in before you executed the begin.

Is it possible that this is what's happening?

Are you trying to do level shifting with the 3904s

Then I set them as input in setup().

Is this a bad solution? The board I purchased was designed this way. Here is the schematic for reference.

No, I see now but what voltage is VCC_UP when you cut power?

In general it's not a good idea to have a non-powered device connected to a powered device unless you can assure that all signal connections are in a high impedance state without any possible parasitic connections to ground or power.

However, in this powered-off state, I measured an unusual voltage (~0.4V) on the uC RX pin (which should be 0V).

For exactly that reason, it is a very bad idea to connect powered MCUs to unpowered modules via I/O pins. You can damage one or both by excessive current flow through I/O pins. Put the SIM module to sleep instead.

1 Like

VCC_UP is also cut along with VBAT.

This was a tradeoff considering the available GSM board and my current PCB's capability.

I thought, that the TX pin of the uC (RX on the GSM module side) can further provide voltage to the board after VBAT is turned off. However looking at the level-shifter circuit, I thought it will be OK, because:

  • VDD_EXT (1,8V provided by 7080) is 0V in turned off state
  • VCC_UP is 0V, because it is cut along with VBAT

But I failed to see the current path back to uC RX pin.

What kind of excessive current do you have in mind? Voltages are not "mixed" everything operates from VBAT.

It would be great, but unfortunately it's not an option with this configuration.
(the GSM module has onboard regulator and PowerLED which would keep consuming if the voltage from the module is not turned off)

If you can use SMD devices, TI has several logic devices with an I-off feature. When the device is unpowered the output is a high impedance with no path to Vcc or ground, just like an open switch. I use then all the time to isolate powered and unpowered devices.

Current flowing from an MCU output pin that is HIGH into an unpowered device I/O pin is guaranteed to exceed the manufacturer's specifications for both devices.

Did you check the schematic? The RX/TX level-shifter transistors prevent any voltage reaching the unpowered SIM7080.

The schematic isn't complete and doesn't much sense.

Since you don't understand the circuit behavior either, I wish you good luck with your project.

The full schematic can be found in post #5.

Really?

I meant the chip, not the board itself.

That depends on what VCC_UP is connected to.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.