Connection detection method and system of mobile terminal based on USB interface charger
Technical Field
The invention relates to the technical field of mobile terminals, in particular to a charging debugging method and system of a mobile terminal based on a USB.
Background
At present, a rechargeable battery is commonly used in a mobile terminal, and therefore, charging is one of the most commonly used functions of the mobile terminal. Charging has been regarded by manufacturers of mobile terminals because of problems relating to battery life, safety of use, and the like. The most common method of charging is to charge the mobile terminal through a charger.
In the prior art, the USB interface of the mobile terminal includes four pins, which are respectively: a VBUS end, a GND end, a DP end and a DN end; the charger is a USB interface, the USB interface of the charger comprises four pins of a VBUS ' end, a GND ' end, a DP ' end and a DN ' end, wherein the DP ' end and the DN ' end are in direct connection, namely in a short-circuit state, and the VBUS ' end always outputs 5V voltage; when the mobile terminal is connected with the charger, the mobile terminal detects 5V voltage on the VBUS end firstly according to the prior art, then detects the states of the DP end and the DN end, and when the mobile terminal is in a short-circuit state, the mobile terminal identifies equipment connected with the USB interface as a standard charger; the steps of the above process are as follows:
s0, four pins of the USB interface of the mobile terminal comprise a VBUS end, a DP end, a DN end and a GND end, four pins of the USB interface of the charger comprise a VBUS 'end, a GND' end, a DP 'end and a DN' end, and when the mobile terminal is connected with the charger, the pins are sequentially connected with each other;
s1, when the mobile terminal detects the rising edge interrupt of VBUS end (low level changes to high level), it goes to step S2;
and S2, the mobile terminal detects whether the DP end and the DN end are short-circuited, if so, the mobile terminal identifies that the equipment connected with the USB interface is a standard charger.
It can be seen that the prior art detection for the standard charger mainly includes steps S1 and S2, and step S1 must be performed first, and then step S2 must be performed; however, in practical situations, due to the long-term use of the charger, the charger is difficult to avoid problems, such as poor contact at the VBUS 'end, or problems occurring in the charger circuit, which results in no output voltage or low output voltage at the VBUS' end; at this time, if the charger is connected to the mobile terminal, step S1 will not be triggered, and the mobile terminal does not have any response, so the mobile terminal cannot determine whether the charger is connected to the mobile terminal.
Accordingly, the prior art is yet to be improved and developed.
Disclosure of Invention
The technical problem to be solved by the present invention is to provide a connection detection method and system for a mobile terminal based on a USB interface charger, which determine whether the charger and the mobile terminal are in a connected or disconnected state according to whether the level of the DP end of the USB interface of the mobile terminal is a low level or a high level, so as to effectively avoid the situation that the VBUS 'end does not output voltage or the output voltage is low due to poor contact of the VBUS' end of the USB interface of the charger or a problem occurs in a charger circuit, and bring convenience to effective charging of the mobile terminal.
The technical scheme adopted by the invention for solving the technical problem is as follows:
a connection detection method of a mobile terminal based on a USB interface charger comprises the following steps:
step A, detecting whether a DP end of a USB interface of the mobile terminal generates rising edge interruption or falling edge interruption;
step B, after detecting that the DP end of the USB interface of the mobile terminal is interrupted, judging whether the level of the DP end is a low level or a high level;
and step C, if the level of the DP end is judged to be low level, the charger is judged to be plugged in, and if the level is high level, the charger is judged to be pulled out.
The mobile terminal is based on a connection detection method of a USB interface charger, wherein the rising edge is interrupted to be a process of changing from a low level to a high level, and the falling edge is interrupted to be a process of changing from the high level to the low level.
The mobile terminal is based on a connection detection method of a USB interface charger, wherein,
the USB interface of the mobile terminal comprises four pins which are respectively as follows: a VBUS end, a GND end, a DP end and a DN end; the charger USB interface includes four pins, is respectively: VBUS ', GND', DP 'and DN' ends; when the mobile terminal is connected with the charger, the pins are sequentially connected with each other.
The mobile terminal is based on a connection detection method of a USB interface charger, wherein the USB interface of the mobile terminal further comprises a resistor, and the DP end, the resistor and a power supply are sequentially connected in series; the DN terminal is connected with the ground.
The mobile terminal is based on a connection detection method of a USB interface charger, wherein when the mobile terminal is not connected with the charger, a DP end of a USB interface of the mobile terminal is at a high level, and a DN end of the USB interface of the mobile terminal is at a low level.
The mobile terminal is based on a connection detection method of a USB interface charger, wherein a DP 'end and a DN' end pin are in short circuit in the charger USB interface, namely the DP 'end and the DN' end pin in the charger USB interface are connected.
The connection detection method of the mobile terminal based on the USB interface charger, wherein the step C specifically comprises the following steps:
c1, the charger USB interface shorts the DP 'end with the DN' end, when the charger is connected with the mobile terminal, the DP end and the DN end in the mobile terminal USB interface are shorted, so that the DP end and the DN end are both changed into low level, the DP end in the mobile terminal USB interface is changed from high level to low level, namely the falling edge is interrupted, and the charger is judged to be inserted into the mobile terminal;
and C2, when the charger is pulled out from the mobile terminal, the DP end of the mobile terminal changes from low level to high level, namely the rising edge is interrupted, thereby judging that the charger is disconnected with the mobile terminal.
A connection detection system of a mobile terminal based on a USB interface charger comprises:
the detection module is used for detecting whether rising edge interruption or falling edge interruption is generated on a DP end of a USB interface of the mobile terminal;
the judging module is used for judging whether the level of the DP end is a low level or a high level after detecting that the DP end of the USB interface of the mobile terminal is interrupted;
and the judging module is used for judging that the charger is plugged in if the level of the DP end is judged to be low level, and judging that the charger is pulled out if the level is high level.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein the judging module specifically comprises:
the connection judging unit is used for short-circuiting the DP 'end and the DN' end in the USB interface of the charger, when the charger is connected with the mobile terminal, the DP end and the DN end in the USB interface of the mobile terminal are short-circuited, so that the DP end and the DN end are both changed into low levels, the DP end in the USB interface of the mobile terminal is changed from high levels to low levels, namely, the falling edge is interrupted, and the charger is judged to be inserted into the mobile terminal;
and the disconnection judging unit is used for changing the DP end of the mobile terminal from low level to high level when the charger is pulled out of the mobile terminal, namely, the rising edge is interrupted, so that the disconnection of the charger and the mobile terminal is judged.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein the rising edge interruption is a process of changing from low level to high level, and the falling edge interruption is a process of changing from high level to low level.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein,
the USB interface of the mobile terminal comprises four pins which are respectively as follows: a VBUS end, a GND end, a DP end and a DN end; the charger USB interface includes four pins, is respectively: VBUS ', GND', DP 'and DN' ends; when the mobile terminal is connected with the charger, the pins are sequentially connected with each other.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein the USB interface of the mobile terminal also comprises a resistor, and the DP end and the resistor are sequentially connected with a power supply in series; the DN terminal is connected with the ground.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein when the mobile terminal is not connected with the charger, a DP end of the USB interface of the mobile terminal is at a high level, and a DN end is at a low level.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein a DP 'end and a DN' end pin are in short circuit in the charger USB interface, namely the DP 'end and the DN' end pin in the charger USB interface are connected.
The invention discloses a connection detection method and a connection detection system of a mobile terminal based on a USB interface charger, wherein the method comprises the following steps: detecting whether rising edge interruption or falling edge interruption is generated on a DP end of a USB interface of the mobile terminal; when detecting that the DP end of the USB interface of the mobile terminal is interrupted, judging whether the level of the DP end is a low level or a high level; and if the level of the DP end is judged to be low level, the charger is judged to be plugged in, and if the level is high level, the charger is judged to be pulled out. The invention judges whether the charger and the mobile terminal are in a connection state or a disconnection state according to whether the level of the DP end of the USB interface of the mobile terminal is low level or high level, can effectively avoid the condition that the VBUS end does not output voltage or the output voltage is lower due to poor contact of the VBUS end of the USB interface of the charger or the problem of a charger circuit, and brings convenience for the effective charging of the mobile terminal.
Drawings
Fig. 1 is a flowchart of a connection detection method for a mobile terminal based on a USB interface charger according to a preferred embodiment of the present invention.
Fig. 2 is a block diagram of a connection detection system of a USB interface charger of a mobile terminal according to the present invention.
Fig. 3 is a schematic diagram of a USB interface of the charger.
Fig. 4 is a functional block diagram of a preferred embodiment of the connection detection system of the mobile terminal based on the USB interface charger according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer and clearer, the present invention is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a connection detection method for a mobile terminal based on a USB interface charger according to a preferred embodiment of the present invention.
As shown in fig. 1, a method for detecting connection of a mobile terminal based on a USB interface charger according to an embodiment of the present invention includes the following steps:
step S100, detecting whether a rising edge interrupt or a falling edge interrupt occurs on a DP terminal of the USB interface of the mobile terminal.
In practical applications, the most common method for charging the mobile terminal is to charge the mobile terminal through a charger. In the present invention, as shown in fig. 2 and 3: the USB interface of the mobile terminal comprises four pins which are respectively as follows: a VBUS end, a GND end, a DP end and a DN end; the charger USB interface includes four pins, is respectively: VBUS ', GND', DP 'and DN' ends; when the mobile terminal is connected with the charger, the pins are sequentially connected with each other. The bus power supply indicates that the equipment power comes from VBUS end, USB interface output voltage is 5V, GND end represents ground connection, DP end represents the positive pole, DN end represents the negative pole.
The USB interface of the mobile terminal further includes a resistor, as shown in fig. 2, the DP terminal, the resistor and the power supply are sequentially connected in series; the DN terminal is connected with the ground. The resistance of the resistor is 200k ohm and the voltage of the power supply is 1.8V.
In the present invention, the rising edge interrupts a process of changing from a low level to a high level, and the falling edge interrupts a process of changing from a high level to a low level.
Step S200, after detecting that the DP end of the USB interface of the mobile terminal is interrupted, judging whether the level of the DP end is low level or high level.
In the invention, when the mobile terminal is not connected with the charger, the DP end of the USB interface of the mobile terminal is at a high level, and the DN end is at a low level; the DP 'end and the DN' end are short-circuited in the charger USB interface, namely the DP 'end and the DN' end in the charger USB interface are connected.
In step S300, if the level of the DP terminal is determined to be low, it is determined that the charger is plugged in, and if the level is high, it is determined that the charger is unplugged.
In the invention, a DP 'end and a DN' end are short-circuited in a charger USB interface, when the charger is connected with a mobile terminal, the DP end and the DN end in the mobile terminal USB interface are short-circuited, so that the DP end and the DN end are both changed into low levels, the DP end of the mobile terminal USB interface is changed from high level to low level, namely, the falling edge is interrupted, and the charger is judged to be inserted into the mobile terminal; when the charger is pulled out of the mobile terminal, the DP end of the USB interface of the mobile terminal is changed from low level to high level, namely, the rising edge is interrupted, so that the disconnection between the charger and the mobile terminal is judged.
The detection module is used for detecting whether the DP end of the USB interface of the mobile terminal generates interruption or not; wherein the interrupt is a rising edge or falling edge interrupt. As described above, when the mobile terminal is connected to the charger, a falling edge interrupt is generated, or when the mobile terminal is disconnected from the charger, a rising edge interrupt is generated, both of which are captured by the detection module; and when the detection module captures the interrupt, the detection module informs the judgment module to further read the level state of the DP end of the USB interface of the mobile terminal.
The judging module is used for judging the connection state of the current charger and the mobile terminal, judging that the charger is plugged in if the connection state is high level, and judging that the charger is unplugged if the connection state is low level.
Based on the above embodiments, the present invention further provides a connection detection system of a mobile terminal based on a USB interface charger, please refer to fig. 4, and fig. 4 is a functional schematic block diagram of a preferred embodiment of the connection detection system of the mobile terminal based on the USB interface charger according to the present invention.
As shown in fig. 4, the system includes:
the detecting module 410 is configured to detect whether a rising edge interrupt or a falling edge interrupt is generated on a DP end of a USB interface of the mobile terminal; as described above.
The determining module 420 is configured to determine whether a level of a DP terminal is a low level or a high level when detecting that a DP terminal of a USB interface of the mobile terminal is interrupted; as described above.
The determining module 430 is configured to determine that the charger is plugged in if the level of the DP terminal is determined to be a low level, and determine that the charger is unplugged if the level is a high level; as described above.
Further, the mobile terminal is based on a connection detection system of a USB interface charger, wherein the determining module specifically includes:
the connection judging unit is used for short-circuiting the DP 'end and the DN' end in the USB interface of the charger, when the charger is connected with the mobile terminal, the DP end and the DN end in the USB interface of the mobile terminal are short-circuited, so that the DP end and the DN end are both changed into low levels, the DP end in the USB interface of the mobile terminal is changed from high levels to low levels, namely, the falling edge is interrupted, and the charger is judged to be inserted into the mobile terminal; as described above.
The disconnection judging unit is used for changing the DP end of the mobile terminal from low level to high level when the charger is pulled out of the mobile terminal, namely, the rising edge is interrupted, so that the disconnection of the charger and the mobile terminal is judged; as described above.
The mobile terminal is based on a connection detection system of a USB interface charger, wherein the rising edge is interrupted in a process of changing from low level to high level, and the falling edge is interrupted in a process of changing from high level to low level; as described above.
In summary, the present invention discloses a connection detection method and system for a mobile terminal based on a USB interface charger, wherein the method comprises: detecting whether rising edge interruption or falling edge interruption is generated on a DP end of a USB interface of the mobile terminal; when detecting that the DP end of the USB interface of the mobile terminal is interrupted, judging whether the level of the DP end is a low level or a high level; and if the level of the DP end is judged to be low level, the charger is judged to be plugged in, and if the level is high level, the charger is judged to be pulled out. The invention judges whether the charger and the mobile terminal are in a connection state or a disconnection state according to whether the level of the DP end of the USB interface of the mobile terminal is low level or high level, can effectively avoid the condition that the VBUS end does not output voltage or the output voltage is lower due to poor contact of the VBUS end of the USB interface of the charger or the problem of a charger circuit, and brings convenience for the effective charging of the mobile terminal.
Of course, it will be understood by those skilled in the art that all or part of the processes of the methods of the above embodiments may be implemented by a computer program instructing relevant hardware (such as a processor, a controller, etc.), and the program may be stored in a computer readable storage medium, and when executed, the program may include the processes of the above method embodiments. The storage medium may be a memory, a magnetic disk, an optical disk, etc.
It is to be understood that the invention is not limited to the examples described above, but that modifications and variations may be effected thereto by those of ordinary skill in the art in light of the foregoing description, and that all such modifications and variations are intended to be within the scope of the invention as defined by the appended claims.