attiny1634 and CP2102 "USB - TTL" chip interfacing and serial line switch

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Freaks,

 

First time using this form so please ignore and forgive me if you find mistakes because its urgent for me if I can get help from this form :)

 

I am working on a USB device which should have capability to communicate serially with computer as well as with other our custom device so this is high level overview.

USB device communicate via CP2102 with computer but our custom device communicate at TTL level with USB device therefore when USB device connected to our device then USB MCU disable CP2102 IC and should communicate directly with our device at TTL level but its not happing because transistor Q3 not activating on setting MCU PIN PA2 to LOW.

 

USB device has two three ICs, - attiny1634, CP2102 and 25LC256 SPI EEPROM.  Now see what I am trying to do - as you can see in schematic CP2102 IC  pins D+, D- directly connected to Male USB connector and RXD, TXD of attiny1634 directly connected to CP2102 but RXD, TXD of attiny1634 also connected to Male USB connector via transistors. Now what actually happening is - I am able to power on off CP2102 IC using transistor Q1, Q4 also able to switch on off transistor Q2. But unable to switch on Q3 transistor so it is always off. PA2 PIN of attiny1634 is always set as output and logic low so it should enable transistor Q3 but its not doing as expected. One more thing I notice if I connect base pin of Q3 transistor directly to GND then Q3 switch on. Attached schematic pdf

 

I wrote a simple code to test Q2, Q3 transistors only. Please see attached Schematic and code.

 

#include <avr/io.h>

#define CTRL_1        PA1
#define CTRL_2        PA2
#define CP_PWR        PA3
#define CP_GND        PA4

int main(void)
{
    DDRA |= (1 << CTRL_1);
    DDRA |= (1 << CTRL_2);
    DDRA |= (1 << CP_PWR);
    DDRA |= (1 << CP_GND);

    /* ENABLE Transistor Q2, Q3 */
    
    PORTA &= ~(1 << CTRL_1);    // This Q2 transistor working on setting LOW.    
    PORTA &= ~(1 << CTRL_2);  // This Q3 transistor not working on setting LOW.
    
     /*  Disabled Transistor Q1, Q4 */
     
    PORTA |= (1 << CP_PWR);            // Set high to disbale Q1 PNP
    PORTA &= ~(1 << CP_GND);            // Set LOW to disbale Q4 NPN
    
    
    while (1) 
    {
        
    }
}

 

 

Attachment(s): 

This topic has a solution.

VP

Last Edited: Tue. Jul 16, 2019 - 03:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See what happens when you try to do something weird? 

Switching the gnd of the cp2102 is most likely going to cause issues as there are substrate diodes on the pins of most cmos ics. These cause stray current paths.

 

The first suggestion that comes to mind is to use bilateral switches like the 74HC4066 on the usb signals.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BJTs don't seem adequate for this IMO. I think Q2 and Q3 should be replaced by analog switches, maybe something classic like the 74HC4053.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings and welcome to AVR Freaks.

 

You have a MAJOR problem. The attiny1634 does NOT have a USB interface so it MUST NOT connect to the USB connector. You connect CP2102 TXD to the RXD pin of a 1634 UART and you connect CP2102 RXD to TXD of the same 1634 UART. It will not work the you have the schematic.

 

The standard procedure is to power the USB interface from USB so that it uses power ONLY when USB is connected. Then, use the presence or absence of USB power to control what the microcontroller does.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would you want to switch power to the USB interface on and off when it has those wonderful SUSPEND pins?

 

I use the 210x family of devices and they are a breeze to use.

 

You are making things too complicated.

 

Another Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for reply, I am not using SUSPEND PINS because still there still is some voltage on D- and D+ that can effect RXD and TXD line on MCU connected via transistor Q2, Q3. BUT my problem with Q3 and rest of circuit working properly. and last but important Thing is our custom device has USB female port and its D- and D+ pin connected RXD , TXD pin of that MCU used in custom device so no option for me.

VP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

VPSR wrote:

I am working on a USB device which should have capability to communicate serially with computer as well as with other our custom device so this is high level overview.

USB device communicate via CP2102 with computer but our custom device communicate at TTL level with USB device therefore when USB device connected to our device then USB MCU disable CP2102 IC and should communicate directly with our device at TTL level.... 

 

The CP2102 has a RESET pin, if you want to disable that device, why not simply pull the RST pin low ? - do not expect GND and VCC switches to work !!

Direct connect to USB pins, is also going to need care, as USB checks for pullups, to decide on USB mode.

As others have mentioned, look at analog switches, and there are USB specified Analog switches available.

 

eg 74AHC1G66 is SPST Analog, and 74LVC1G3157 is SPDT Analog.

A SPDT switch allows you to steer USB pins to  the target device, and isolate from the unused chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks :)

 

Let me explain again, Why I am doing this weird thing because we have a device which has USB female port and its D-, D+ pin directly connected to RXD, TXD pins of micro controller used in device so at computer side I have to use CP2102 IC to communicate but at that device side we have TTL type serial therefore I have to disable CP2102 IC  via attniy1634 firmaware when it is connected to it.

 

Rest of circuit working except transistor Q3 and one thing I checked after post is that even if MCU pin PA2 is set OUPUT LOW it showing +ve 4.05V, thats wired because its PNP transistor and voltage should be low at base with respect to its collector or emitter. Last thing is that USB device I am making should work as I explained no other option for otherwise would have done it before.

Simple goal is whenever this USB circuit get power up then attiny1634 by default will keep CP2102 IC disabled and will wait for 5 seconds for reply from that custom made device if it gets reply then USB will be in direct TTL mode if it doesn't get reply within 5 seconds then it will shift to computer mode and will disable Q2, Q3 and will enable CP2102 IC.

VP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks :)

 

I ll check and update results on form.

VP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, I think analog switch can help will update results but if you can help on around Q3 because other option will take at least 1 week including component delivery so I have no option for now...need some transistoryyy guy :D

VP

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

VPSR wrote:

ok, I think analog switch can help will update results but if you can help on around Q3 because other option will take at least 1 week including component delivery so I have no option for now...need some transistoryyy guy :D

VPSR wrote:

Rest of circuit working except transistor Q3 and one thing I checked after post is that even if MCU pin PA2 is set OUPUT LOW it showing +ve 4.05V, thats wired because its PNP transistor and voltage should be low at base with respect to its collector or emitter. Last thing is that USB device I am making should work as I explained no other option for otherwise would have done it before.

If the MCU pin measures 4.05V in CMOS out mode, driving LOW, something is strongly pulling it hi. Shift to another port pin ?

PNP Trx do actually work in both directions, but the Hfe is lower reversed. 

With a CMOS drive, you should be ok to common the MCU end of PNP base resistors, and so use just one pin.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Hello Raving Lunati,  you genius saved me :D

 

what you said I did and it did not worked :( BUT :) I connect both PA1 and PA2 to each other via 1K resistor before R4 and R5 resistor connected to base of Q2, Q3 and it worked :D yey!!

 

actually by connecting in this way it helps to pull down base of Q3 because +ve voltage coming from TXD of MCU to collector of Q3 trying to sink to its base and its gets more GND now so Q3 switched on :D

 

Simple any pin port register set to logic low means register pin connected to gnd internally and in this case we have two pins so we got two ground source it helps to pull down base of Q3 :D

 

Big Thanks to you and all

VP