Multiplexer switch works partially

A while ago I had posted on stackexchange to get comments on how I can switch between a USB-UART bridge and a Bluetooth module for wireless Arduino control (custom Arduino, 5V, 16Mhz running grbl). I finally built the design and for the most part it works. I can communicate with the sketch through the serial port. However, I'm not able to program the Arduino through either the USB-UART bridge or the Bluetooth. The BT module is set to 115200 baud on both the device and in Windows settings. Arduino shows the following error:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x11

Can anyone help me troubleshoot this? I made a few changes to the schematic and here is the updated version:

From what I see the voltage on Vbus is always going to be high, either through a 10k resistor or directly to the supply from the USB.

That error message is telling you the computer is getting no response from the Arduino

The VBUS voltage is affected by R3-R6. That's fine, so far, as the signal may go down to 5/4V, but I'm not sure what Q1 and U1-U3 think about such a level.

Nonetheless the switches should work with USB Vcc applied, as can be verified from the successful connection to the sketch. I'd inspect the Reset signal, eventually the U3 resistance is too high for causing proper reset?
Is programming via USB possible after manual (button) reset?

Grumpy_Mike:
From what I see the voltage on Vbus is always going to be high, either through a 10k resistor or directly to the supply from the USB.

My bad! I had modified the circuitry that turns off the BT module when a USB cable is plugged in. The way its on the board is as shown below.

DrDiettrich:
The VBUS voltage is affected by R3-R6. That's fine, so far, as the signal may go down to 5/4V, but I'm not sure what Q1 and U1-U3 think about such a level.

Nonetheless the switches should work with USB Vcc applied, as can be verified from the successful connection to the sketch. I'd inspect the Reset signal, eventually the U3 resistance is too high for causing proper reset?
Is programming via USB possible after manual (button) reset?

Hmmm. No I cannot program after a manual reset either. How do I find U3's resistance?

Get a scope and check the reset pulse, generated from DTR. This will tell more than the U3 resistance, which should be mentioned in the datasheet.

OK let me try and map it on the scope. I'm assuming you are talking about the ON resistance? Thats listed as 6.5 ohms for Vcc of 4-5V. Not sure what that means in this context though.

Circuit still not right. When VBUS is at 5V Q2 is on and the gate of Q1 sits at 2.5V, which must be on the threshold so it is probably partly on. When VBUS is at 0V then Q2 is off and so the gate of Q1 sits at 0V turning the power to the bluetooth off.
Should the gate of Q2 not be connected to the collector of Q1 and R10 removed?

I notice there are no decoupling capacitors shown, I am assuming that they are present but just not shown on the diagram.

DrDiettrich:
Get a scope and check the reset pulse, generated from DTR. This will tell more than the U3 resistance, which should be mentioned in the datasheet.

OK I just tried this again with a scope. When I click on 'Upload' the DTR pin goes low and the multiplexer output also goes low. Hence on the MUX side of the 0.1u capacitor the voltage is 0V however, on the RESET pin side it remains at 5V. Also the USB-UART is a CP2104 which is a 3.3V device. Hence a 'high' signal is 3.3V.

Grumpy_Mike:
Circuit still not right. When VBUS is at 5V Q2 is on and the gate of Q1 sits at 2.5V, which must be on the threshold so it is probably partly on. When VBUS is at 0V then Q2 is off and so the gate of Q1 sits at 0V turning the power to the bluetooth off.
Should the gate of Q2 not be connected to the collector of Q1 and R10 removed?

I notice there are no decoupling capacitors shown, I am assuming that they are present but just not shown on the diagram.

I just simulated this in LTSpice (file attached). You are right about removing the R10 on the collector of Q1. Also Q2's gate is connected on the emitter of Q1 and not the collector.

P-MOSFET switch.zip (677 Bytes)

Hence on the MUX side of the 0.1u capacitor the voltage is 0V however, on the RESET pin side it remains at 5V.

Sounds like you need to make that capacitor bigger, try a 1uF.

Grumpy_Mike:
Sounds like you need to make that capacitor bigger, try a 1uF.

Still doesn't work. I get the same error with a different resp code:

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xc7

Still doesn't work.

Yes but are you seeing a pulse on the reset line?

Also the USB-UART is a CP2104 which is a 3.3V device.

And it is happy to get a 5V signal on its input? And being fed a 5V power supply?

I see a level shift rather than a pulse. The DTR line drops to 0V the moment Arduino attempts to program the board. Yes the CP2104 is 5V tolerant though I'm not sure if it has enough current sourcing capabilities on its UART lines. The UART lines follow the Vio voltage on the device and this is being powered by an onboard 3.3V regulator which in turn is being powered by the main 5V supply. The Vio voltage cannot exceed 3.46V making this a 3.3V device.

Do I need a level shifter between the CP2104 DTR and that RESET cap?

Also you can one time configure the CP2104 UART lines to be either push pull or open drain outputs. The default configuration is push pull output and I've not changed those defaults.

A reliable circuit requires proper level shifting between 3.3V and 5V components. I'd suggest that you do everything right in the first place, before you start optimizing for lower power consumption, component count or price.

I see a level shift rather than a pulse. The DTR line drops to 0V the moment Arduino attempts to program the board.

Yes but the other side of the capacitor, the reset pin should have a pulse on it that you can see with a scope.
The capacitor forms a differentiator circuit and turns the level shift of the DTR line into a pulse to reset the Arduino. If that pulse is not long enough or does not drop below the zero threshold your Arduino will not be reset and you will get the error message that you do.

Right! that does not happen in my case but let me verify that again. I see that the RESET pin level remains steady at 5V.

I see that the RESET pin level remains steady at 5V.

And you know how to set up your scope's trigger to see the fast reset pulse don't you?

That was going to be my next Q :slight_smile: Could you please let me know how to capture that?

What sort of scope you you have?
The pulse will be very fleeting and will not repeat.

On a two channel storage scope:-
Basically set the trigger on the channel looking at the DTR signal and set to one shot. Then adjust the trigger level to half way. Now look at the other side of the capacitor, the reset pin, with the other channel.

On a one channel storage scope:-
Set the trigger on the channel looking reset pin and set to one shot. Then adjust the trigger level to just under the 5V level.

In both the above you will see the reset pulse. Make sure the reset pulse reaches down to 0.5V or below, and lasts at lease 2.5uS.

On a one channel none storage scope:-
Set up as a one channel storage scope, but turn up the brightness and view in a darkened room.

From a 3.3V DTR signal you cannot get a 4.5V Reset spike (down to 0.5V), only down to 2V :frowning:

OK the programming now works albeit very erratically. On some boards it does not. I uninstalled Arduino and cleaned out the preferences folder in Appdata. I reinstalled everything and now it works. The reset cap is now a 1uF.

However, I'm still curious about seeing the reset pulse but I'm not able to capture it. Here is what I'm doing. I have a Rigol DS1054Z DSO. I set the Trigger type to edge, Mode to Single and Slope to rising edge. The Horizontal scale is set at 5ms and the vertical is at 1V. I set the trigger to 4.6V and nothing showed.

Also the level on the reset pin is being shown at a constant 120mV. Isn't this considered logic low? This should mean the Arduino is in a state of constant reset.