Electrical – Enable DTR/RESET by software with an ATMega328 MCU

atmegareset

I’m building a project using an ATMega328, and for the serial communication and programming it, I’ve connected a USB CP2102 controller.
The problem with atmega328 (and all arduino boards) is that the MCU resets whenever the system sends signals to the DTR pin of the serial port, for example when we have the device always connected to the USB port of a PC and the computer restarts or powers on, the MCU resets itself.
To avoid this behavior, I have a physical switch which opens and closes the DTR connection from the USB module to the MCU reset pin, which works quite well.

enter image description here

My question is, how can I get rid of the physical switch and have the functionality to enable/disable the DTR to reset connection by software using an MCU pin?

I tried by using a NAND gate with 2 NPN transistors with inputs the DTR and a digital pin and output to reset pin, but it didn’t work well.

EDIT:

I am aware of altering the USB port driver files and disabling the DTR, and the RSTDISBL fuse flag, which both are not what I’m looking for. I need a simple way to enable/disable the DTR/reset connection by software and a MCU pin.

Best Answer

Do you mean something like this?

When "CONTROL" is driven HIGH:

DTR is HIGH, the N-FET is OFF (Vgs = 0), and RST is HIGH.

DTR is LOW, the N-FET is ON (Vgs = 5V)and pulling RST LOW.

When "CONTROL" is driven LOW:

DTR is HIGH, the N-FET is OFF (Vgs = -5V), RST is HIGH.

DRT is LOW, the N-FET is OFF (Vgs = 0V), RST is HIGH.

When "CONTROL" is in high impedance state:

R3 pulls N-FETs gate up, connecting DTR and RST when DTR goes LOW.

So basically, when CONTROL is HIGH, DTR is enabled.

schematic

simulate this circuit – Schematic created using CircuitLab