Abstract:
A USB device and a detection method therefor. It can be detected whether the USB device is a master device or a slave device without the use of an ID pin, thereby saving the pin resources of the USB device. The USB device comprises: a series branch formed by a first pull-up resistor (R 1 ) and a first switch (S 1 ) and having one end connected to VCC and the other end connected to a D+ or D− data line; a series branch formed by a second pull-up resistor (R 2 ) and a second switch (S 2 ) and having one end connected to the VCC and the other end connected to the D+ data line; a series branch formed by a third pull-up resistor (R 3 ) and a third switch (S 3 ) and having one end connected to VCC and the other end connected to the D− data line; a series branch formed by a fourth pull-up resistor (R 4 ) and a fourth switch (S 4 ) and having one end being grounded and the other end connected to the D+ data line; and a series branch formed by a fifth pull-up resistor (R 5 ) and a fifth switch (S 5 ) and having one end being grounded and the other end connected to the D− data line. The USB device belongs to the field of communication devices.

Description:
[0001]    The present application is a US National Stage of International Application No. PCT/CN2011/082826, filed 24 Nov. 2011, designating the United States, and claiming priority to Chinese Patent Application No. 201010557614.1, filed with the State Intellectual Property Office of China on Nov. 24, 2010 and entitled “USB device and detection method thereof”, which is hereby incorporated by reference in its entirety. 
     
    
     FIELD OF THE INVENTION 
       [0002]    The present invention relates to the field of communication devices and particularly to a USB device and a method for detecting the USB device. 
       BACKGROUND OF THE INVENTION 
       [0003]    A Universal Serial Bus (USB) device in compliance with the USB 2.0 specification is typically a Dual Role Device (DRD) device, which can be acted as a master device, also can be acted as a slave device. As illustrated in  FIG. 1   a , which is a schematic structural diagram of a USB device in compliant with the USB 2.0 specification, connection pins of the USB device include a VBUS pin, an ID pin, a GND pin and D+ and D− pins, and the USB device internally includes a data transceiver circuit having outputs connected to the D+ pin and D− pin through D+ data line and D− data line and a VBUS drive control module connected to the VBUS pin through a VBUS data line, where the D+ data line is grounded through a pull-down resistor R 4  and a switch S 4 , and the D− data line is grounded through a pull-down resistor R 5  and a switch S 5 , and if the USB device is a high-speed or full-speed device, then the D+ data line is connected to a power supply VCC through a pull-up resistor R 1  and a switch S 1 , and if the USB device is a low-speed device, then the D− data line is connected to VCC through the pull-up resistor R 1  and the switch S 1  as illustrated in  FIG. 1   b.    
         [0004]    The existing USB DRD identifies whether the present USB device is a master device or a slave device at a specific time point by taking a level of the ID pin among the connection pins of the USB device as a criterion so that the USB device is a USB slave device if the level of the ID pin is a high level and a master device if level of the ID pin is a low level. However, this detection method has such a drawback that a resource of one pin in a chip of the USB device has to be occupied, because the ID pin is required in the USB device. 
       SUMMARY OF THE INVENTION 
       [0005]    The invention provides a USB device and a method for detecting the USB device so that whether the USB device is a master device or a slave device can be detected without an ID pin to thereby save a pin resource of the USB device. 
         [0006]    A USB device includes: a data transceiver circuit having outputs connected respectively with D+ and D− data lines; and a VBUS drive control module, wherein the USB device further includes: 
         [0007]    a first pull-up resistor, a second pull-up resistor, a third pull-up resistor, a first switch, a second switch, and a third switch, wherein a series branch, composed of the first pull-up resistor and the first switch, having one end connected with a VCC and the other end connected with the D+ data line or the D− data line, a series branch, composed of the second pull-up resistor and the second switch, having one end connected with the VCC and the other end connected with the D+ data line, and a series branch, composed of the third pull-up resistor and the third switch, having one end connected with the VCC and the other end connected with the D− data line; and 
         [0008]    a fourth pull-down resistor, a fifth pull-down resistor, a fourth switch and a fifth switch, wherein a series branch, composed of the fourth pull-down resistor and the fourth switch, having one end grounded and the other end connected with the D+ data line, and a series branch, composed of the fifth pull-down resistor and the fifth switch, having one end grounded and the other end connected with the D− data line. 
         [0009]    A method for detecting the USB device includes: 
         [0010]    controlling the first pull-up resistor on the D+ data line or the D− data line of the USB device to be switched off, the fourth pull-down resistor on the D+ data line to be switched off and the fifth pull-down resistor on the D− data line to be switched off, and enabling the second pull-up resistor on the D+ data line and the third pull-up resistor on the D− data line, wherein when the first pull-up resistor and the fourth pull-down resistor on the D+ data line are switched on concurrently, or when the first pull-up resistor and the fifth pull-down resistor on the D− data line are switched on concurrently, a voltage on the first pull-up resistor is in a range of logically low levels, and when the second pull-up resistor and the fourth pull-down resistor on the D+ data line are switched on concurrently, or when the third pull-up resistor and the fifth pull-down resistor on the D− data line are switched on concurrently, a voltage on the fourth pull-down resistor or the fifth pull-down resistor is in a range of logically low levels; 
         [0011]    controlling an output voltage of the VBUS drive control module to be 0; and 
         [0012]    detecting level statuses of the D+ data line and the D− data line of the USB device, and determining the USB device as a slave device upon determining D+=0 and D−=0. 
         [0013]    A method for detecting the USB device includes: 
         [0014]    controlling the first pull-up resistor on the D+ data line or the D− data line of the present USB device to be switched off, and enabling the second pull-up resistor and the fourth pull-down resistor on the D+ data line and the third pull-up resistor and the fifth pull-down resistor on the D− data line of the USB device, wherein when the first pull-up resistor and the fourth pull-down resistor on the D+ data line are switched on concurrently, or when the first pull-up resistor and the fifth pull-down resistor on the D− data line are switched on concurrently, a voltage on the first pull-up resistor is in a range of logically low levels, and when the second pull-up resistor and the fourth pull-down resistor on the D+ data line are switched on concurrently, or when the third pull-up resistor and the fifth pull-down resistor on the D− data line are switched on concurrently, a voltage on the fourth pull-down resistor or the fifth pull-down resistor is in a range of logically low levels; 
         [0015]    controlling an output voltage of the VBUS drive control module to be valid; and detecting level statuses of the D+ data line and the D− data line of the present USB device, and determining the present USB device as a master device upon determining D+=0 and D−=1, or D+=1 and D−=0. 
         [0016]    With the USB device according to the embodiment of the invention, the pull-up resistor R 2  and the switch S 2  are added on the D+ data line, the pull-up resistor R 3  and the switch S 3  are added on the D− data line, the statuses of the pull-up resistors R 1 , R 2  and R 3  and the pull-down resistors R 4  and R 5  are controlled, and the output voltage of the VBUS drive control module is controlled to be valid or not, so that whether the USB device is a master device or a slave device can be detected without an ID pin to thereby save a pin resource of the USB device. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0017]      FIG. 1   a  is a schematic structural diagram of a high-speed USB device in the prior art; 
           [0018]      FIG. 1   b  is a schematic structural diagram of a low-speed USB device in the prior art; 
           [0019]      FIG. 2   a  is a structural diagram of a first USB device according to an embodiment of the invention; 
           [0020]      FIG. 2   b  is a structural diagram of a second USB device according to an embodiment of the invention; 
           [0021]      FIG. 3  is a flow chart of a first method for detecting a USB device according to an embodiment of the invention; 
           [0022]      FIG. 4  is a flow chart of a second method for detecting a USB device according to an embodiment of the invention; 
           [0023]      FIG. 5  is a schematic diagram of connecting the present USB device with a master device; 
           [0024]      FIG. 6  is a schematic diagram of connecting the present USB device with a USB high-speed or full-speed slave device; and 
           [0025]      FIG. 7  is a schematic diagram of connecting the present USB device with a USB low-speed slave device. 
       
    
    
     DETAILED DESCRIPTION OF THE EMBODIMENTS 
       [0026]    An USB device according to embodiments of the invention further includes a pull-up resistor R 2  and a switch S 2  on the D+ data line and a pull-up resistor R 3  and a switch S 3  on the D− data line in addition to the existing USB device. 
         [0027]      FIG. 2   a  illustrates a first USB device according to an embodiment of the invention, which is a high-speed or full-speed USB device, where pins of the USB device include a VBUS pin, D+ and D− pins, and a GND pin, and the USB device includes: 
         [0028]    a data transceiver circuit having outputs connected to the D+ and D− pins of the USB device through D+ and D− data lines; 
         [0029]    a VBUS drive control module having an output connected to the VBUS pin of the USB device through a VBUS data line; 
         [0030]    a series branch, composed of a pull-up resistor R 1  and a controllable switch S 1 , having one end connected to a power supply VCC (e.g., 3.3V) and the other end connected to the D+ data line; 
         [0031]    a series branch, composed of a pull-up resistor R 2  and a controllable switch S 2 , having one end connected to the power supply VCC and the other end connected to the D+ data line, and a series branch, composed of a pull-up resistor R 3  and a controllable switch S 3 , having one end connected to the power supply VCC and the other end connected to the D− data line; and 
         [0032]    a series branch, composed of a pull-down resistor R 4  and a controllable switch S 4 , having one end grounded and the other end connected to the D+ data line, and a series branch, composed of a pull-down resistor R 5  and a controllable switch S 5 , having one end grounded and the other end connected to the D− data line. 
         [0033]    The resistance of the pull-up resistor R 1  is the minimum, and the resistances of the pull-down resistors R 4  and R 5  are on the same order of magnitude and far above the resistance of the pull-up resistor R 1  to ensure that a voltage on the pull-up resistor R 1  is in a range of logically low levels when the pull-up resistor R 1  and the pull-down resistor R 4  or R 5  are switched on concurrently, that is, the voltage on the pull-up resistor R 1  is almost 0 when R 1  and R 4  are switched on concurrently, where the pull-up resistor R 1  can be several kilohms, and the resistances of the pull-down resistors R 4  and R 5  are at least 10 times the pull-up resistor R 1  and can be several tens of kilohms, typically R 1  is approximately 1.5KΩ, and R 4  and R 5  are approximately 15KΩ. 
         [0034]    The resistances of pull-up resistors R 2  and R 3  are on the same order of magnitude and far above the resistances of R 4  and R 5  to ensure that a voltage on the pull-down R 4  or R 5  is in a range of logically low levels when the pull-up resistor R 2  and the pull-down resistor R 4  on the D+ data line are switched on concurrently or when the pull-up resistor R 3  and the pull-down resistor R 5  on the D− data line are switched on concurrently, where the resistances of the pull-up resistors R 2  and R 3  are at least 10 times the resistance of R 4  or R 5  and can be several hundreds of kilohms, typically approximately 300KΩ. 
         [0035]      FIG. 2   b  illustrates a second USB device according to an embodiment of the invention, which is a low-speed USB device and different from the USB device of  FIG. 2   a  in that the series branch composed of the pull-up resistor R 1  and the controllable switch S 1  has one end connected to the power supply VCC and the other end connected to the D− data line. 
         [0036]      FIG. 3  illustrates a flow chart of a first method for detecting the USB device according to an embodiment of the invention, which includes the following steps. 
         [0037]    S 301  is to control the USB device to be powered on. 
         [0038]    S 302  is to control the pull-up resistor R 1  on the D+ data line or the D− data line of the USB device to be switched off, the pull-down resistor R 4  on the D+ data line to be switched off and the pull-down resistor R 5  on the D− data line to be switched off, and to enable the pull-up resistor R 2  on the D+ data line and the pull-up resistor R 3  on the D− data line. 
         [0039]    To enable a pull-up resistor or a pull-down resistor refers to connecting the pull-up resistor or the pull-down resistor into a circuit, that is, connecting the switch corresponding to the pull-up resistor or the pull-down resistor in  FIG. 2 . 
         [0040]    To switch off a pull-up resistor or a pull-down resistor refers to disconnecting a switch corresponding to the pull-up resistor or the pull-down resistor. 
         [0041]    If the D+ data line is connected with the pull-up resistor R 1  and when the pull-up resistor R 1  and the pull-down resistor R 4  are switched on concurrently, or if the D− data line is connected with the pull-up resistor R 1  and when the pull-up resistor R 1  and the pull-down resistor R 5  are switched on concurrently, a voltage on the pull-up resistor R 1  is in a range of logically low levels, and when the pull-up resistor R 2  and the pull-down resistor R 4  on the D+ data line are switched on concurrently, or when the pull-up resistor R 3  and the pull-down resistor R 5  on the D− data line are switched on concurrently, a voltage on the pull-down resistor R 4  or the pull-down resistor R 5  is in a range of logically low levels. 
         [0042]    Preferably, the resistances of the pull-down resistors R 4  and R 5  are at least 10 times the pull-up resistor R 1 , and the resistances of the pull-up resistors R 2  and R 3  are at least 10 times the pull-down resistors R 4  and R 5 . 
         [0043]    S 303  is to control an output voltage VBUS of the VBUS drive control module to be 0. 
         [0044]    Particularly, firstly the step S 302  and then the step S 303  can be performed or firstly the step S 303  and then the step S 302  can be performed without departing from the scope of the invention. 
         [0045]    S 304  is to detect level statuses of the data lines D+ and D− and to determine whether the level statuses of D+ and D− satisfy D+=0 and D−=0, and if so, the flow goes to the step S 305 ; otherwise, the flow goes to the step S 306 . 
         [0046]    S 305  is to determine the USB device as a slave device and to start an operation flow of a USB slave device, which particularly is a flow in the prior art, and thus a repeated description thereof will be omitted here. 
         [0047]    A determination criterion is that if the USB device is connected with a master device (e.g., a PC), on D+ and D− data lines of the master device there are pull-down resistors pulled down to GND and with the same resistances as R 4  and R 5 , assumed R 1 =1.5K, R 2 , R 3 =300K, and R 4 , R 5 =15K, so the voltages of D+ and D− are approximately 0V, that is, 3.3V*15K/(300K+15K)≈0V. 
         [0048]    As illustrated in  FIG. 5 , which is a schematic diagram of connecting the present USB device with a master device, the D+ and D− data lines of the present USB device are connected respectively with the D+ and D− data lines of the master device, and there are pull-down resistors R 6  and R 7  (the resistance of R 6  is the same as the resistance of R 5 , and the resistance of R 7  is the same as the resistance of R 4 ), pulled down to GND, respectively on the D+ and D− data lines of the master device, so the voltages of D+ and D− are approximately 0V, that is, 3.3V*15K/(300K+15K)≈0V. 
         [0049]    Thus D+=0 and D−=0 indicates that the USB device is connected with a master device, that is, the USB device is a slave device. 
         [0050]    S 306  is to enable the pull-down resistor R 4  on the D+ data line and the pull-down resistor R 5  on the D− data line of the USB device. 
         [0051]    S 307  is to control the output voltage VBUS of the VBUS drive control module to be valid, that is, 4.75V&lt;VBUS&lt;5.25V, and of course, other ranges of values are also possible. 
         [0052]    Particularly, firstly the step S 306  and then the step S 307  can be performed or firstly the step S 307  and then the step S 306  can be performed without departing from the scope of the invention. 
         [0053]    S 308  is to detect the level statuses of the data lines D+ and D− and to determine whether the level statuses of D+ and D− satisfy D+=1 and D−=0 or D+=0 and D−=1, and if so, the flow goes to the step S 309 ; otherwise, the flow returns to the step S 302  for further detection. 
         [0054]    If not so, it indicates that there is currently no USB device connected with the present USB device, and the flow will return to the step S 302  for further detection. 
         [0055]    S 309  is to determine the USB device as a master device and to start an operation flow of a USB master device, which particularly is a flow in the prior art, and thus a repeated description thereof will be omitted here. 
         [0056]    A determination criterion here is that a USB slave device shall enable the pull-up resistor R 1  on the D+ or D− data line within a specific period of time after valid VBUS is detected, as stipulated in the USB specification. 
         [0057]    As illustrated in  FIG. 6 , which is a schematic diagram of connecting the present USB device with a USB high-speed or full-speed slave device, D+, D−, GND and VBUS of the present USB device are connected respectively with D+, D−, GND and VBUS of the slave device, and since the output voltage VBUS of the present USB device is valid, a pull-up resistor R 9  of the slave device is connected to the D+ data line, and the slave device enables R 9  (the resistance of R 9  is the same as the resistance of the pull-up resistor R 1 ), and then the voltage of D+ is approximately 3V, that is, 3.3V*15K/(1.5K+15K)≈3V, i.e., a logically high level of 1, and D− is still in a status of approximately 0V, that is, D+=1 and D−=0. 
         [0058]    As illustrated in  FIG. 7 , which is a schematic diagram of connecting the present USB device with a USB low-speed slave device, D+, D−, GND and VBUS of the present USB device are connected respectively with D+, D−, GND and VBUS of the slave device; and a pull-up resistor R 8  of the slave device is connected to the D− data line, and the slave device enables R 8  (the resistance of R 8  is the same as the resistance of the pull-up resistor R 1 ), and then the voltage of D− is approximately 3V, that is, 3.3V*15K/(1.5K+15K)≈3V, i.e., a logically high level of 1, and D+ is still in a status of approximately 0V, that is, D+=0 and D−=1. 
         [0059]    Thus D+=1 and D−=0 or D+=0 and D−=1 indicates that the USB device is connected with a slave device, that is, the USB device is a master device. 
         [0060]    Preferably, in the steps S 304  and S 308 , a delay time can be set before the level statuses of the data lines D+ and D− are detected, and the level statuses of the data lines D+ and D− are detected after the level statuses of the D+ and D− data lines settle down after the set delay time. 
         [0061]    In the foregoing method, firstly whether the USB device is a slave device is determined, and if not, whether the USB device is a master device is determined, and of course, it is also possible to determine firstly whether the USB device is a master device and then whether the USB device is a slave device. 
         [0062]      FIG. 4  illustrates a flow chart of a second method for detecting the USB device according to an embodiment of the invention, which includes the following steps. 
         [0063]    S 401  is to control the USB device to be powered on. 
         [0064]    S 402  is to control the pull-up resistor R 1  on the D+ data line or the D− data line of the USB device to be switched off and to enable the pull-up resistor R 2  and the pull-down resistor R 4  on the D+ data line and the pull-up resistor R 3  and the pull-down resistor R 5  on the D− data line of the USB device. 
         [0065]    If the D+ data line is connected with the pull-up resistor R 1  and when the pull-up resistor R 1  and the pull-down resistor R 4  are switched on concurrently, or if the D− data line is connected with the pull-up resistor R 1  and when the pull-up resistor R 1  and the pull-down resistor R 5  are switched on concurrently, a voltage on the pull-up resistor R 1  is in a range of logically low levels, and when the pull-up resistor R 2  and the pull-down resistor R 4  on the D+ data line are switched on concurrently, or when the pull-up resistor R 3  and the pull-down resistor R 5  on the D− data line are switched on concurrently, a voltage on the pull-down resistor R 4  or the pull-down resistor R 5  is in a range of logically low levels. 
         [0066]    Preferably, the resistances of the pull-down resistors R 4  and R 5  are at least 10 times the pull-up resistor R 1 , and the resistances of the pull-up resistors R 2  and R 3  are at least 10 times the pull-down resistors R 4  and R 5 . 
         [0067]    S 403  is to control an output voltage of the USB drive control module to be valid, that is, 4.75V&lt;VBUS&lt;5.25V, and of course, other ranges of values are also possible. 
         [0068]    Particularly, firstly the step S 402  and then the step S 403  can be performed or firstly the step S 403  and then the step S 402  can be performed without departing from the scope of the invention. 
         [0069]    S 404  is to detect level statuses of the D+ data line and the D− data line of the USB device and to determine whether the level statuses of D+ and D− satisfy D+=1 and D−=0 or D+=0 and D−=1, and if so, the flow goes to the step S 405 ; otherwise, the flow goes to the step S 406 . 
         [0070]    S 405  is to determine the USB device as a master device and to start an operation flow of a USB master device. 
         [0071]    S 406  is to switch off the pull-down resistor R 4  on the D+ data line and the pull-down resistor R 5  on the D− data line of the USB device. 
         [0072]    S 407  is to control the output voltage VBUS of the VBUS drive control module to be 0. 
         [0073]    Particularly, firstly the step S 406  and then the step S 407  can be performed or firstly the step S 407  and then the step S 406  can be performed without departing from the scope of the invention. 
         [0074]    S 408  is to detect the level statuses of the D+ and D− data lines of the USB device and to determine whether the level statuses of D+ and D− satisfy D+=0 and D−=0, and if so, the flow goes to the step S 409 ; otherwise, the flow returns to the step S 402  for further detection. 
         [0075]    If not so, it indicates that there is currently no USB device connected with the present USB device, and the flow will return to the step S 402  for further detection. 
         [0076]    S 409  is to determine the USB device as a slave device and to start an operation flow of a USB slave device. 
         [0077]    Preferably, in the steps S 404  and S 408 , a delay time can be set before the level statuses of the data lines D+ and D− are detected, and the level statuses of the data lines D+ and D− are detected after the level statuses of the D+ and D− data lines settle down after the set delay time 
         [0078]    When the present USB device and the opposite USB device are connected and adopt the same detection method, if both of the USB devices start detection concurrently (that is, perform the step S 302  or the step S 402  concurrently), both of the USB devices may determine themselves as a master device concurrently, thus the connection is invalid, and therefore have to restart detection, thus lowering the efficiency of the connection. Referring to  FIG. 3 , if the present USB device and the opposite USB device connected therewith are structurally identical and perform the step S 302  in the detection method concurrently, each of the USB devices determines itself not as a slave device and outputs the valid voltage VBUS to the other while enabling the resistors R 4  and R 5 , and both of the USB devices shall enable the pull-on resistor R 1  on the D+ or D− data line within a specific period of time after the valid VBUS is detected, and thus in the step S 309 , both of them determine themselves as a master device, thus the connection is invalid. Referring to  FIG. 4 , if the present USB device and the opposite USB device connected therewith are structurally identical and perform the step S 402  and the step S 403  in the same method concurrently, each of the USB devices outputs the valid voltage VBUS to the other, and both of the USB devices shall enable the pull-on resistor R 1  on the D+ or D− data line within a specific period of time after the valid VBUS is detected, and thus in the step S 405 , both of them determine themselves as a master device, thus the connection is invalid. 
         [0079]    Preferably, in an embodiment of the invention, when both of the USB devices adopt the same detection method, the present USB device is configured with such a trigger condition that the present USB device does not start detection concurrently with the opposite USB device and to perform the step S 302  when the trigger condition is satisfied so that the present USB device will not start detection concurrently with the opposite USB device. Specifically, for example, detection is configured to start upon reception of an external control signal, and thus the control signal can be input to control the two devices so that they will not perform detection concurrently, or detection is configured to start upon arrival of a preset timing, and the two devices are configured with different preset timings, thereby also ensuring that the two devices will not perform detection concurrently. 
         [0080]    With the USB device and the detection method according to the embodiments of the invention, whether the USB device acts as a master device or a slave device can be identified automatically only using VBUS and the D+ and D− data lines without detecting a level status of the ID pin. Thus a resource of one pin can be saved in a chip of the USB DRD without influencing the performance of the USB device. 
         [0081]    Evidently those skilled in the art can make various modifications and variations to the invention without departing from the scope of the invention. Thus the invention is also intended to encompass these modifications and variations thereto as long as these modifications and variations come into the scope of the claims appended to the invention and their equivalents.