CN116303151A - Data transmission method, device and storage medium - Google Patents

Data transmission method, device and storage medium Download PDF

Info

Publication number
CN116303151A
CN116303151A CN202211091849.5A CN202211091849A CN116303151A CN 116303151 A CN116303151 A CN 116303151A CN 202211091849 A CN202211091849 A CN 202211091849A CN 116303151 A CN116303151 A CN 116303151A
Authority
CN
China
Prior art keywords
data
timer
transmitted
transmission
mode
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211091849.5A
Other languages
Chinese (zh)
Inventor
周丽
昌明涛
尤淇
阳婧
王能申
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Gree Electric Appliances Inc of Zhuhai
Zhuhai Zero Boundary Integrated Circuit Co Ltd
Original Assignee
Gree Electric Appliances Inc of Zhuhai
Zhuhai Zero Boundary Integrated Circuit Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Gree Electric Appliances Inc of Zhuhai, Zhuhai Zero Boundary Integrated Circuit Co Ltd filed Critical Gree Electric Appliances Inc of Zhuhai
Priority to CN202211091849.5A priority Critical patent/CN116303151A/en
Publication of CN116303151A publication Critical patent/CN116303151A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/10Program control for peripheral devices
    • G06F13/12Program control for peripheral devices using hardware independent of the central processor, e.g. channel or peripheral processor
    • G06F13/124Program control for peripheral devices using hardware independent of the central processor, e.g. channel or peripheral processor where hardware is a sequential transfer control unit, e.g. microprocessor, peripheral processor or state-machine
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/14Handling requests for interconnection or transfer
    • G06F13/16Handling requests for interconnection or transfer for access to memory bus
    • G06F13/1668Details of memory controller
    • G06F13/1689Synchronisation and timing concerns
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Microelectronics & Electronic Packaging (AREA)
  • Communication Control (AREA)

Abstract

The application relates to the technical field of computer communication, in particular to a data transmission method, a data transmission device and a storage medium, which solve the problems of higher communication cost and higher communication consumption hardware cost in the prior art. The method comprises a data transmission process and a data receiving process; while waiting to receive data, the control timer turns on the capture function, waiting for the arrival of a falling edge, ensuring that during this period the microprocessor is not occupied and other transactions can be processed. When the receiving pin detects that a falling edge arrives, the timer is triggered to capture the falling edge and generate an interrupt so as to start receiving data, and meanwhile, the timer is switched to a timing function until the receiving is completed. When transmitting data, only the timing function of the timer needs to be turned on. Therefore, the microprocessor only needs to wait for receiving signals to temporarily start working in the communication process, so that the resources of the microprocessor are saved to a great extent.

Description

Data transmission method, device and storage medium
Technical Field
The present disclosure relates to the field of computer communications technologies, and in particular, to a data transmission method, apparatus, and storage medium.
Background
To meet the requirements of different industries and different applications, the embedded system needs to have efficient design and high tailorability. In order to ensure the endurance and reliability of the embedded system, practical problems such as low power consumption, small volume, high integration level and the like are necessarily listed as the primary conditions for the development of the embedded equipment.
A microprocessor or microcontroller (Microcontroller Unit, MCU), i.e. a single chip microcomputer. After the MCU is designed, generated and produced, the hardware resources are fixed, and the different hardware resources are used differently. Generally, the MCU has several hardware communication modes, such as IIC and SPI, and the MCU will be used with the peripheral devices during communication, and each use of one hardware communication means that the hardware resources are occupied. In practical applications, communications between multiple embedded devices are often encountered, however, increasing the communication mode means increasing the communication cost and consuming hardware resources.
Disclosure of Invention
Aiming at the problems of higher communication cost and higher communication consumption hardware cost in the prior art, the application provides a data transmission method, a data transmission device and a storage medium.
In a first aspect, the present application provides a data transmission method, including a data transmission process and a data reception process;
The data transmission process comprises the following steps:
controlling the timer to be in a timing mode;
acquiring data to be transmitted and corresponding preset transmission data quantity;
transmitting the data to be transmitted according to the timing time of the timer;
acquiring the current transmitted data volume, and determining whether to finish data transmission according to the current transmitted data volume and the preset transmitted data volume;
the data receiving process comprises the following steps:
controlling the timer to be in a capturing mode;
when the timer captures a falling edge, controlling the timer to switch into a timing mode, and simultaneously receiving data according to the timing time of the timer;
and acquiring the current received data length, and determining whether the data reception is completed or not according to the current received data length and the preset data length.
In the above embodiment, the method configures the function of the timer in the process of data transmission, and uses different interrupt behaviors of the timer to realize the transceiving of data between devices in a common input/output pin. While waiting to receive data, the control timer turns on the capture function, waiting for the arrival of a falling edge, ensuring that during this period the microprocessor is not occupied and other transactions can be processed. When the receiving pin detects that a falling edge arrives, the timer is triggered to capture the falling edge and generate an interrupt so as to start receiving data, and meanwhile, the timer is switched to a timing function until the receiving is completed. When transmitting data, only the timing function of the timer needs to be turned on. Therefore, the microprocessor only needs to wait for receiving signals to temporarily start working in the communication process, so that the resources of the microprocessor are saved to a great extent.
According to an embodiment of the present application, optionally, in the data transmission method, in the data transmission process, the step of determining whether to complete data transmission according to the current transmitted data amount and the preset transmission data amount includes:
judging whether the transmitted data volume is larger than or equal to the preset transmitted data volume or not;
if the transmitted data amount is not greater than or equal to the preset transmitted data amount, the step of transmitting the data to be transmitted according to the timing time of the timer is transferred;
if the transmitted data amount is greater than or equal to the preset transmission data amount, closing a timer to finish the data transmission process.
According to an embodiment of the present application, optionally, in the data transmission method, after the step of obtaining the data to be transmitted in the data transmission process, before the step of transmitting the data to be transmitted according to the timing time of the timer, the method further includes:
and processing the data to be transmitted according to a Universal Asynchronous Receiver Transmitter (UART) transmission format.
According to an embodiment of the present application, optionally, in the above data transmission method, before the step of acquiring the data to be transmitted in the data transmission process, the method further includes:
Acquiring a target transmission mode, wherein the target transmission mode comprises a blocking mode or a no-waiting mode;
the step of transmitting the data to be transmitted according to the timing time of the timer comprises the following steps:
and transmitting the data to be transmitted by adopting the target transmission mode according to the timing time of the timer.
According to an embodiment of the present application, in the foregoing data transmission method, when the target transmission mode is a blocking mode in the data transmission process, the step of transmitting the data to be transmitted by using the target transmission mode according to the timing time of the timer includes:
the transmit status bit is enabled and the data to be transmitted for one frame is transmitted by bit.
According to an embodiment of the present application, in the data transmission method, when the target transmission mode is a no-waiting mode in the data transmission process, the step of transmitting the data to be transmitted by using the target transmission mode according to the timing time of the timer includes:
enabling a sending status bit and sending the data to be sent;
judging whether the transmission is overtime or not when the data to be transmitted are transmitted;
If the sending time is overtime, ending sending the data to be sent;
and if the sending is judged not to be overtime, the step of sending the data to be sent is transferred.
According to an embodiment of the present application, optionally, in the data transmission method, in the data receiving process, the step of determining whether to complete data receiving according to the currently received data length and a preset data length includes:
judging whether the received data length is larger than a preset data length or not;
if the received data length is not greater than the preset data length, turning to a step of receiving data according to the timing time of the timer;
if the received data length is greater than the preset data length, the method goes to the step of controlling the timer to be in the capturing mode.
According to an embodiment of the present application, optionally, in the above data transmission method, when the timer captures a falling edge, a start bit is detected;
the step of receiving data according to the timing time of the timer comprises the following steps:
after the timer generates a third interrupt, changing the acquisition control variable to 2 and starting the acquisition of other data during the second acquisition; wherein the other data includes data bits and stop bits, or the other data includes valid data bits, parity bits, and stop bits.
In a second aspect, the present application further provides a data transmission apparatus, including:
the data transmission process comprises the following steps:
the first timer control module is used for controlling the timer to be in a timing mode;
the data to be transmitted acquisition module is used for acquiring data to be transmitted and corresponding preset transmission data quantity;
the data transmitting module is used for transmitting the data to be transmitted according to the timing time of the timer;
the data transmission completion judging module is used for acquiring the current transmitted data quantity and determining whether the data transmission is completed or not according to the current transmitted data quantity and the preset transmitted data quantity;
the data receiving process comprises the following steps:
the second timer control module is used for controlling the timer to be in a capturing mode;
the data receiving control module is used for controlling the timer to switch into a timing mode when the falling edge is captured by the timer, and simultaneously receiving data according to the timing time of the timer;
and the data receiving completion judging module is used for acquiring the current received data length and determining whether the data receiving is completed or not according to the current received data length and the preset data length.
According to an embodiment of the present application, optionally, in the data transmission device, in the data transmission process, the data transmission completion judging module includes:
A transmission data amount judgment unit configured to judge whether the transmitted data amount is greater than or equal to the preset transmission data amount;
a data sending unit, configured to, if the sent data amount is not greater than or equal to the preset sending data amount, switch to a step of sending the data to be sent according to the timing time of the timer;
and the transmission ending control unit is used for closing a timer to end the data transmission process if the transmitted data quantity is greater than or equal to the preset transmission data quantity.
According to an embodiment of the present application, optionally, in the data transmission device, in the data transmission process, the device further includes:
and the transmission data processing module is used for processing the data to be transmitted according to a Universal Asynchronous Receiver Transmitter (UART) transmission format.
According to an embodiment of the present application, optionally, in the foregoing data transmission apparatus, in the data transmission process, the apparatus further includes:
a target transmission mode acquisition module, configured to acquire a target transmission mode, where the target transmission mode includes a blocking mode or a no-waiting mode;
the data transmitting module includes:
and the sending unit is used for sending the data to be sent by adopting the target sending mode according to the timing time of the timer.
According to an embodiment of the present application, optionally, in the data transmission device, when the target transmission mode is a blocking mode in the data transmission process, the transmitting unit includes:
and the first transmitting subunit is used for enabling the transmission of the status bit and transmitting the data to be transmitted of one frame according to the bit.
According to an embodiment of the present application, in the above data transmission apparatus, when the target transmission mode is a no-wait mode in the data transmission process, the transmitting unit may include:
a second transmitting subunit, configured to enable to transmit a status bit, and transmit the data to be transmitted;
the timeout judging subunit is used for judging whether the transmission is overtime or not when the data to be transmitted are transmitted;
an ending control subunit, configured to end sending the data to be sent if it is determined that the sending is overtime;
and the second sending subunit is used for switching to the step of sending the data to be sent if the sending is judged not to be overtime.
According to an embodiment of the present application, optionally, in the data transmission device, in the data receiving process, the data receiving completion judging module includes:
a data length judging unit for judging whether the received data length is greater than a preset data length;
The data receiving control unit is used for switching to the step of receiving data according to the timing time of the timer if the received data length is not more than the preset data length;
and the second timer control unit is used for switching to the step of controlling the timer to be in the capturing mode if the received data length is greater than the preset data length.
According to an embodiment of the present application, optionally, in the above data transmission device, when the timer captures a falling edge, a start bit is detected;
the data receiving control module includes:
the data acquisition unit is used for changing the acquisition control variable to 2 and starting the acquisition of other data in the second acquisition after the timer generates the third interrupt; wherein the other data includes data bits and stop bits, or the other data includes valid data bits, parity bits, and stop bits.
In a third aspect, the present application provides a storage medium storing a computer program executable by one or more processors for implementing a data transmission method as described above.
In a fourth aspect, the present application provides an electronic device, including a memory and a processor, where the memory stores a computer program, and the computer program, when executed by the processor, performs the data transmission method described above.
One or more embodiments of the above-described solution may have the following advantages or benefits compared to the prior art:
the application provides a data transmission method, a data transmission device and a storage medium, wherein the method comprises a data transmission process and a data receiving process; the data transmission process comprises the following steps: controlling the timer to be in a timing mode; acquiring data to be transmitted and corresponding preset transmission data quantity; transmitting the data to be transmitted according to the timing time of the timer; acquiring the current transmitted data volume, and determining whether to finish data transmission according to the current transmitted data volume and the preset transmitted data volume; the data receiving process comprises the following steps: controlling the timer to be in a capturing mode; when the timer captures a falling edge, controlling the timer to switch into a timing mode, and simultaneously receiving data according to the timing time of the timer; and acquiring the current received data length, and determining whether the data reception is completed or not according to the current received data length and the preset data length. The method configures the function of the timer in the process of data transmission, and utilizes different interrupt behaviors of the timer to realize the transceiving of data between devices in a common input/output pin. While waiting to receive data, the control timer turns on the capture function, waiting for the arrival of a falling edge, ensuring that during this period the microprocessor is not occupied and other transactions can be processed. When the receiving pin detects that a falling edge arrives, the timer is triggered to capture the falling edge and generate an interrupt so as to start receiving data, and meanwhile, the timer is switched to a timing function until the receiving is completed. When transmitting data, only the timing function of the timer needs to be turned on. Therefore, the microprocessor only needs to wait for receiving signals to temporarily start working in the communication process, so that the resources of the microprocessor are saved to a great extent.
Drawings
The present application will be described in more detail hereinafter based on embodiments and with reference to the accompanying drawings.
Fig. 1 is a flowchart of a data transmission method according to an embodiment of the present application.
Fig. 2 is another flow chart of a data transmission method according to an embodiment of the present application.
Fig. 3 is another flow chart of a data transmission method according to an embodiment of the present application.
Fig. 4 is a connection block diagram of an electronic device according to a second embodiment of the present application.
In the drawings, like parts are given like reference numerals, and the drawings are not drawn to scale.
Detailed Description
The following will describe embodiments of the present application in detail with reference to the drawings and examples, thereby how to apply technical means to the present application to solve technical problems, and realizing processes achieving corresponding technical effects can be fully understood and implemented accordingly. The embodiments and the features in the embodiments can be combined with each other under the condition of no conflict, and the formed technical schemes are all within the protection scope of the application.
Example 1
The invention provides a data transmission method, please refer to fig. 1 and 2, which includes a data transmission process and a data receiving process;
The data transmission process comprises the following steps:
step S110: controlling the timer to be in a timing mode;
step S120: acquiring data to be transmitted and corresponding preset transmission data quantity;
step S130: transmitting the data to be transmitted according to the timing time of the timer;
step S140: and acquiring the current transmitted data quantity, and determining whether the data transmission is completed or not according to the current transmitted data quantity and the preset transmitted data quantity.
In the data transmission process, the step S140 of determining whether to complete data transmission according to the current transmitted data amount and the preset transmitted data amount includes the following steps:
step S141: judging whether the transmitted data volume is larger than or equal to the preset transmitted data volume or not;
step S142: if the transmitted data amount is not greater than or equal to the preset transmitted data amount, the step of transmitting the data to be transmitted according to the timing time of the timer is transferred;
step S143: if the transmitted data amount is greater than or equal to the preset transmission data amount, closing a timer to finish the data transmission process.
In the above embodiment, the timer is controlled by judging whether the amount of transmitted data is greater than or equal to the preset amount of transmitted data, so as to realize control of data transmission and stop transmission.
As an embodiment, after the step of acquiring the data to be transmitted in the data transmission process, before the step of transmitting the data to be transmitted according to the timing time of the timer, the data to be transmitted may be processed in a universal asynchronous receiver Transmitter (Universal Asynchronous Receiver/Transmitter, UART) transmission format.
In the above embodiment, the universal asynchronous receiving and transmitting protocol can process serial/parallel, parallel/serial conversion between the data bus and the serial port, and prescribe a frame format. The two communication parties can complete data transmission between devices by only using two signal wires under the condition of not sharing clock signals only by adopting the same frame format and baud rate, thereby effectively reducing the communication cost.
The data receiving process comprises the following steps:
step S210: controlling the timer to be in a capturing mode;
step S220: when the timer captures a falling edge, controlling the timer to switch into a timing mode, and simultaneously receiving data according to the timing time of the timer;
step S230: and acquiring the current received data length, and determining whether the data reception is completed or not according to the current received data length and the preset data length.
According to an embodiment of the present application, optionally, in the data transmission method, in the data receiving process, the step S230 of determining whether to complete data receiving according to the currently received data length and a preset data length includes the following steps:
step S231: judging whether the received data length is larger than a preset data length or not;
step S232: if the received data length is not greater than the preset data length, turning to a step of receiving data according to the timing time of the timer;
step S233: if the received data length is greater than the preset data length, the method goes to the step of controlling the timer to be in the capturing mode.
In the above embodiment, the timer is controlled by determining whether the received data length is greater than the preset data length, so as to realize control of data reception and stop of reception.
According to an embodiment of the present application, optionally, in the above data transmission method, when the timer captures a falling edge, a start bit is detected; the step of receiving data according to the timing time of the timer comprises the following steps: after the timer generates a third interrupt, changing the acquisition control variable to 2 and starting the acquisition of other data during the second acquisition; wherein the other data includes data bits and stop bits, or the other data includes valid data bits, parity bits, and stop bits.
Wherein, in the data transmission process and the data receiving process, the timer may be an enhanced timer.
In summary, the present application provides a data transmission method, which includes a data sending process and a data receiving process; the data transmission process comprises the following steps: controlling the timer to be in a timing mode; acquiring data to be transmitted and corresponding preset transmission data quantity; transmitting the data to be transmitted according to the timing time of the timer; acquiring the current transmitted data volume, and determining whether to finish data transmission according to the current transmitted data volume and the preset transmitted data volume; the data receiving process comprises the following steps: controlling the timer to be in a capturing mode; when the timer captures a falling edge, controlling the timer to switch into a timing mode, and simultaneously receiving data according to the timing time of the timer; and acquiring the current received data length, and determining whether the data reception is completed or not according to the current received data length and the preset data length. The method configures the function of the timer in the process of data transmission, and utilizes different interrupt behaviors of the timer to realize the transceiving of data between devices in a common input/output pin. While waiting to receive data, the control timer turns on the capture function, waiting for the arrival of a falling edge, ensuring that during this period the microprocessor is not occupied and other transactions can be processed. When the receiving pin detects that a falling edge arrives, the timer is triggered to capture the falling edge and generate an interrupt so as to start receiving data, and meanwhile, the timer is switched to a timing function until the receiving is completed. When transmitting data, only the timing function of the timer needs to be turned on. Therefore, the microprocessor only needs to wait for receiving signals to temporarily start working in the communication process, so that the resources of the microprocessor are saved to a great extent.
Example two
On the basis of the first embodiment, the present embodiment describes the method in the first embodiment by way of specific embodiments.
In the data transmission process, before the step of acquiring the data to be transmitted, the method further includes:
acquiring a target transmission mode, wherein the target transmission mode comprises a blocking mode or a no-waiting mode;
the step of transmitting the data to be transmitted according to the timing time of the timer comprises the following steps:
and transmitting the data to be transmitted by adopting the target transmission mode according to the timing time of the timer.
When the data is transmitted in the blocking mode, the current data can be started only after the last data is successfully transmitted, so that the accuracy of the timing time of the enhanced timer can be ensured as much as possible, and the bit width error can be reduced. When data is transmitted in the wait-less mode, the transmission is determined to be overtime and is exited without completing the transmission for a predetermined time. Two different transmission modes are selected when in transmission to meet the requirements of different applications.
As one embodiment, when the target transmission mode is a blocking mode, the step of transmitting the data to be transmitted using the target transmission mode according to the timing time of the timer includes:
The transmit status bit is enabled and the data to be transmitted for one frame is transmitted by bit.
As another embodiment, when the target transmission mode is a no-wait mode, the step of transmitting the data to be transmitted in the target transmission mode according to the timing time of the timer includes:
enabling a sending status bit and sending the data to be sent;
judging whether the transmission is overtime or not when the data to be transmitted are transmitted;
if the sending time is overtime, ending sending the data to be sent;
and if the sending is judged not to be overtime, the step of sending the data to be sent is transferred.
Example III
On the basis of the first embodiment, the present embodiment describes the method in the first embodiment by way of specific embodiments.
The microprocessor can realize half-duplex communication between the MCUs according to the UART transmission protocol by utilizing the enhanced timer and two common input/output pins.
In UART transport format configuration, the baud rate needs to be calculated in advance, and the time length 1/n needed by 1 bit, where n represents the transmission speed. The number of cycles in 1 second of the microprocessor is equal to 1 divided by the system clock frequency, i.e., 1/FCLK. Wherein the timing time of the enhanced timer is equal to the system clock frequency divided by the transmission speed, i.e., FCLK/n, without frequency division.
When the data receiving sampling is set, in order to ensure the accuracy of the data, the timing time of the enhanced timer is FLCK/(2 n), namely the sampling is carried out for 2 times, and when the data receiving device receives the data, the second bit begins to be sampled after 3 times of timing, namely the overflow interruption is carried out, and the later data bit is sampled once every 2 times of overflow interruption.
When data is transmitted, 1 pin of the microprocessor is firstly configured as a transmitting pin, the transmitting pin is initialized to be in a common output mode and in an internal pull-up state, and the output high level is immediately pulled up and kept after the initialization. The timing function of the enhanced timer is enabled prior to transmission.
Before transmission, the transmission data needs to be stored in a transmission array, and the amount of the pre-transmission data is marked.
When data is transmitted, a transmission function is called, and overflow interrupt of the enhanced timer is enabled in the transmission function. According to the amount of data transmitted, the for loop is utilized, and each time 1 data is processed and the transmission is completed, the amount of data is reduced by 1 until the amount of data is 0 and the transmission is completed and exits.
Specifically, the data to be sent is processed in the sending function according to the UART transmission format, the enabling sending state and the enhanced timer calculate to obtain accurate timing time according to a formula, and when two overflow interrupts are generated and the sending state is enabled, the callback function only needs to push the data according to bits until 1 frame of data is pushed. As described above, until all data is transmitted. Thus, the accuracy of the timing time of the enhanced timer can be ensured as much as possible, and the bit width error can be reduced. To meet different application needs, the blocking mode and the no-waiting mode can be selected during transmission.
When data is received, 1 pin of the microprocessor needs to be configured as a receiving pin, the receiving pin is initialized to be in a falling edge interrupt mode and in an internal pull-up state, an information configuration structure of a timer is initialized, and an enhanced timer is configured to be in a capturing mode.
Before receiving data, the receiving end is configured according to the data format of the sending end. And calling a receiving function, initializing a receiving array, setting a receiving mode as a blocking mode, and receiving only 1 frame of data each time, wherein the receiving mode is used for receiving while cycles for a plurality of times. During the reception, the sampling number is 2, and when the arrival of the falling edge is captured, sampling is started, and the reception of data is started when the sampling is 0, and the data is not immediately discarded. Where the sampling is 0, i.e. the sampling of the start bit.
Specifically, when the arrival of the falling edge is captured, the mode of the enhanced timer is switched to be a timing function, and the first sampling of the data is considered, but because the sampling point is positioned at the edge position of the data and is easy to misjudge, the second bit needs to be sampled for 3 times, namely, the third overflow interrupt is used for temporarily sampling, the second bit of the data frame is obtained by sampling, and the starting bit is the first bit.
Starting from the second bit of data, the sampling position is at the middle position, the sampling control variable is changed to 2, namely, the sampling is interrupted once by two overflow processes, and the sampling of the effective data bit is completed.
And after the effective data bit is acquired, continuously receiving the overflow interrupt twice for sampling once to acquire the parity bit, calling a parity check function to check the parity bit, if the error occurs, marking the receiving event state as check error, otherwise, maintaining the receiving event mark. For the parity check, whether to execute or not can be automatically selected according to the transmission format, that is, if no parity is in the transmitted data format, the parity check is not needed.
And finally, receiving a stop bit, wherein if the received data comprises a parity bit, the data can be considered to be successfully received under the condition that the parity bit check is not wrong, and meanwhile, the data is written into a receiving array, and the receiving event is marked as the completion of receiving. If the parity check is wrong, a receiving error is returned. After the current receiving flow is completed, the enhanced timer is switched from the timing mode to the capturing mode, and the next data receiving is waited.
Example IV
Referring to fig. 3, the present application provides a data transmission apparatus 300, which includes:
the data transmission process comprises the following steps:
a first timer control module 310 for controlling the timer to be in a timing mode;
the to-be-transmitted data obtaining module 320 is configured to obtain to-be-transmitted data and a corresponding preset amount of transmitted data;
A data sending module 330, configured to send the data to be sent according to the timing time of the timer;
a data transmission completion judging module 340, configured to obtain a current transmitted data amount, and determine whether to complete data transmission according to the current transmitted data amount and the preset transmitted data amount;
the data receiving process comprises the following steps:
a second timer control module 350 for controlling the timer to be in the capture mode;
a data receiving control module 360, configured to control the timer to switch to a timing mode when the timer captures a falling edge, and simultaneously perform data receiving according to the timing time of the timer;
the data receiving completion judging module 370 is configured to obtain a currently received data length, and determine whether to complete data receiving according to the currently received data length and a preset data length.
According to an embodiment of the present application, optionally, in the data transmission device, in the data transmission process, the data transmission completion judging module includes:
a transmission data amount judgment unit configured to judge whether the transmitted data amount is greater than or equal to the preset transmission data amount;
A data sending unit, configured to, if the sent data amount is not greater than or equal to the preset sending data amount, switch to a step of sending the data to be sent according to the timing time of the timer;
and the transmission ending control unit is used for closing a timer to end the data transmission process if the transmitted data quantity is greater than or equal to the preset transmission data quantity.
According to an embodiment of the present application, optionally, in the data transmission device, in the data transmission process, the device further includes:
and the transmission data processing module is used for processing the data to be transmitted according to a Universal Asynchronous Receiver Transmitter (UART) transmission format.
According to an embodiment of the present application, optionally, in the foregoing data transmission apparatus, in the data transmission process, the apparatus further includes:
a target transmission mode acquisition module, configured to acquire a target transmission mode, where the target transmission mode includes a blocking mode or a no-waiting mode;
the data transmitting module includes:
and the sending unit is used for sending the data to be sent by adopting the target sending mode according to the timing time of the timer.
According to an embodiment of the present application, optionally, in the data transmission device, when the target transmission mode is a blocking mode in the data transmission process, the transmitting unit includes:
And the first transmitting subunit is used for enabling the transmission of the status bit and transmitting the data to be transmitted of one frame according to the bit.
According to an embodiment of the present application, in the above data transmission apparatus, when the target transmission mode is a no-wait mode in the data transmission process, the transmitting unit may include:
a second transmitting subunit, configured to enable to transmit a status bit, and transmit the data to be transmitted;
the timeout judging subunit is used for judging whether the transmission is overtime or not when the data to be transmitted are transmitted;
an ending control subunit, configured to end sending the data to be sent if it is determined that the sending is overtime;
and the second sending subunit is used for switching to the step of sending the data to be sent if the sending is judged not to be overtime.
According to an embodiment of the present application, optionally, in the data transmission device, in the data receiving process, the data receiving completion judging module includes:
a data length judging unit for judging whether the received data length is greater than a preset data length;
the data receiving control unit is used for switching to the step of receiving data according to the timing time of the timer if the received data length is not more than the preset data length;
And the second timer control unit is used for switching to the step of controlling the timer to be in the capturing mode if the received data length is greater than the preset data length.
According to an embodiment of the present application, optionally, in the above data transmission device, when the timer captures a falling edge, a start bit is detected;
the data receiving control module includes:
the data acquisition unit is used for changing the acquisition control variable to 2 and starting the acquisition of other data in the second acquisition after the timer generates the third interrupt; wherein the other data includes data bits and stop bits, or the other data includes valid data bits, parity bits, and stop bits.
In summary, the present application provides a data transmission device, including: the data transmission process comprises the following steps: the first timer control module is used for controlling the timer to be in a timing mode; the data to be transmitted acquisition module is used for acquiring data to be transmitted and corresponding preset transmission data quantity; the data transmitting module is used for transmitting the data to be transmitted according to the timing time of the timer; the data transmission completion judging module is used for acquiring the current transmitted data quantity and determining whether the data transmission is completed or not according to the current transmitted data quantity and the preset transmitted data quantity; the data receiving process comprises the following steps: the second timer control module is used for controlling the timer to be in a capturing mode; the data receiving control module is used for controlling the timer to switch into a timing mode when the falling edge is captured by the timer, and simultaneously receiving data according to the timing time of the timer; and the data receiving completion judging module is used for acquiring the current received data length and determining whether the data receiving is completed or not according to the current received data length and the preset data length. The method configures the function of the timer in the process of data transmission, and utilizes different interrupt behaviors of the timer to realize the transceiving of data between devices in a common input/output pin. While waiting to receive data, the control timer turns on the capture function, waiting for the arrival of a falling edge, ensuring that during this period the microprocessor is not occupied and other transactions can be processed. When the receiving pin detects that a falling edge arrives, the timer is triggered to capture the falling edge and generate an interrupt so as to start receiving data, and meanwhile, the timer is switched to a timing function until the receiving is completed. When transmitting data, only the timing function of the timer needs to be turned on. Therefore, the microprocessor only needs to wait for receiving signals to temporarily start working in the communication process, so that the resources of the microprocessor are saved to a great extent.
Example five
The present embodiment also provides a computer readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, where the computer program when executed by a processor can implement the above method, and the specific embodiment procedure can be referred to the above embodiment, and the description of the embodiment is not repeated herein.
Example six
The embodiment of the application provides an electronic device, which can be a mobile phone, a computer or a tablet computer, and comprises a memory and a processor, wherein the memory stores a computer program, and the computer program is executed by the processor to realize the data transmission method in the first embodiment. It will be appreciated that as shown in fig. 4, the electronic device 400 may further include: a processor 401, a memory 402, a multimedia component 403, an input/output (I/O) interface 404, and a communication component 405.
Wherein the processor 401 is configured to perform all or part of the steps in the data transmission method as in the first embodiment. The memory 402 is used to store various types of data, which may include, for example, instructions for any application or method in the electronic device, as well as application-related data.
The processor 401 may be an application specific integrated circuit (Application Specific Integrated Circuit, abbreviated as ASIC), a digital signal processor (Digital Signal Processor, abbreviated as DSP), a digital signal processing device (Digital Signal Processing Device, abbreviated as DSPD), a programmable logic device (Programmable Logic Device, abbreviated as PLD), a field programmable gate array (Field Programmable Gate Array, abbreviated as FPGA), a controller, a microcontroller, a microprocessor, or other electronic component implementation for performing the data transmission method in the above embodiment.
The Memory 402 may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as static random access Memory (Static Random Access Memory, SRAM for short), electrically erasable programmable Read-Only Memory (Electrically Erasable Programmable Read-Only Memory, EEPROM for short), erasable programmable Read-Only Memory (Erasable Programmable Read-Only Memory, EPROM for short), programmable Read-Only Memory (Programmable Read-Only Memory, PROM for short), read-Only Memory (ROM for short), magnetic Memory, flash Memory, magnetic disk, or optical disk.
The multimedia component 403 may include a screen, which may be a touch screen, and an audio component for outputting and/or inputting audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in a memory or transmitted through a communication component. The audio assembly further comprises at least one speaker for outputting audio signals.
The I/O interface 404 provides an interface between the processor 401 and other interface modules, which may be a keyboard, mouse, buttons, etc. These buttons may be virtual buttons or physical buttons.
The communication component 405 is used for wired or wireless communication between the electronic device 400 and other devices. Wireless communication, such as Wi-Fi, bluetooth, near field communication (Near Field Communication, NFC for short), 2G, 3G or 4G, or a combination of one or more thereof, the corresponding communication component 405 may thus comprise: wi-Fi module, bluetooth module, NFC module.
In summary, the method, the device and the storage medium for data transmission provided by the application comprise a data sending process and a data receiving process; the data transmission process comprises the following steps: controlling the timer to be in a timing mode; acquiring data to be transmitted and corresponding preset transmission data quantity; transmitting the data to be transmitted according to the timing time of the timer; acquiring the current transmitted data volume, and determining whether to finish data transmission according to the current transmitted data volume and the preset transmitted data volume; the data receiving process comprises the following steps: controlling the timer to be in a capturing mode; when the timer captures a falling edge, controlling the timer to switch into a timing mode, and simultaneously receiving data according to the timing time of the timer; and acquiring the current received data length, and determining whether the data reception is completed or not according to the current received data length and the preset data length. The method configures the function of the timer in the process of data transmission, and utilizes different interrupt behaviors of the timer to realize the transceiving of data between devices in a common input/output pin. While waiting to receive data, the control timer turns on the capture function, waiting for the arrival of a falling edge, ensuring that during this period the microprocessor is not occupied and other transactions can be processed. When the receiving pin detects that a falling edge arrives, the timer is triggered to capture the falling edge and generate an interrupt so as to start receiving data, and meanwhile, the timer is switched to a timing function until the receiving is completed. When transmitting data, only the timing function of the timer needs to be turned on. Therefore, the microprocessor only needs to wait for receiving signals to temporarily start working in the communication process, so that the resources of the microprocessor are saved to a great extent.
In the several embodiments provided in the embodiments of the present application, it should be understood that the disclosed systems and methods may be implemented in other manners. The system and method embodiments described above are merely illustrative.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Although the embodiments disclosed in the present application are described above, the descriptions are merely for facilitating understanding of the present application, and are not intended to limit the present application. Any person skilled in the art to which this application pertains will be able to make any modifications and variations in form and detail of implementation without departing from the spirit and scope of the disclosure, but the scope of the patent claims of this application shall be subject to the scope of the claims that follow.

Claims (10)

1. A data transmission method, characterized in that the method comprises a data transmission process and a data reception process;
the data transmission process comprises the following steps:
controlling the timer to be in a timing mode;
acquiring data to be transmitted and corresponding preset transmission data quantity;
transmitting the data to be transmitted according to the timing time of the timer;
acquiring the current transmitted data volume, and determining whether to finish data transmission according to the current transmitted data volume and the preset transmitted data volume;
the data receiving process comprises the following steps:
controlling the timer to be in a capturing mode;
when the timer captures a falling edge, controlling the timer to switch into a timing mode, and simultaneously receiving data according to the timing time of the timer;
and acquiring the current received data length, and determining whether the data reception is completed or not according to the current received data length and the preset data length.
2. The method according to claim 1, wherein in the data transmission process, the step of determining whether to complete data transmission according to the current transmitted data amount and the preset transmission data amount includes:
judging whether the transmitted data volume is larger than or equal to the preset transmitted data volume or not;
If the transmitted data amount is not greater than or equal to the preset transmitted data amount, the step of transmitting the data to be transmitted according to the timing time of the timer is transferred;
if the transmitted data amount is greater than or equal to the preset transmission data amount, closing a timer to finish the data transmission process.
3. The method according to claim 1, wherein, in the data transmission process, after the step of acquiring data to be transmitted, before the step of transmitting the data to be transmitted according to the timing time of the timer, the method further comprises:
and processing the data to be transmitted according to a Universal Asynchronous Receiver Transmitter (UART) transmission format.
4. The method of claim 1, wherein prior to the step of obtaining data to be transmitted during the data transmission, the method further comprises:
acquiring a target transmission mode, wherein the target transmission mode comprises a blocking mode or a no-waiting mode;
the step of transmitting the data to be transmitted according to the timing time of the timer comprises the following steps:
and transmitting the data to be transmitted by adopting the target transmission mode according to the timing time of the timer.
5. The method according to claim 4, wherein, in the data transmission process, when the target transmission mode is a blocking mode, the step of transmitting the data to be transmitted in the target transmission mode according to the timing of the timer includes:
the transmit status bit is enabled and the data to be transmitted for one frame is transmitted by bit.
6. The method according to claim 4, wherein the step of transmitting the data to be transmitted in the target transmission mode according to the timing time of the timer when the target transmission mode is a no-wait mode in the data transmission process includes:
enabling a sending status bit and sending the data to be sent;
judging whether the transmission is overtime or not when the data to be transmitted are transmitted;
if the sending time is overtime, ending sending the data to be sent;
and if the sending is judged not to be overtime, the step of sending the data to be sent is transferred.
7. The method according to claim 1, wherein during the data reception, the step of determining whether to complete data reception according to the currently received data length and a preset data length comprises:
Judging whether the received data length is larger than a preset data length or not;
if the received data length is not greater than the preset data length, turning to a step of receiving data according to the timing time of the timer;
if the received data length is greater than the preset data length, the method goes to the step of controlling the timer to be in the capturing mode.
8. The method of claim 1, wherein a start bit is detected when the timer captures a falling edge;
the step of receiving data according to the timing time of the timer comprises the following steps:
after the timer generates a third interrupt, changing the acquisition control variable to 2 and starting the acquisition of other data during the second acquisition; wherein the other data includes data bits and stop bits, or the other data includes valid data bits, parity bits, and stop bits.
9. A data transmission apparatus, comprising:
the data transmission process comprises the following steps:
the first timer control module is used for controlling the timer to be in a timing mode;
the data to be transmitted acquisition module is used for acquiring data to be transmitted and corresponding preset transmission data quantity;
the data transmitting module is used for transmitting the data to be transmitted according to the timing time of the timer;
The data transmission completion judging module is used for acquiring the current transmitted data quantity and determining whether the data transmission is completed or not according to the current transmitted data quantity and the preset transmitted data quantity;
the data receiving process comprises the following steps:
the second timer control module is used for controlling the timer to be in a capturing mode;
the data receiving control module is used for controlling the timer to switch into a timing mode when the falling edge is captured by the timer, and simultaneously receiving data according to the timing time of the timer;
and the data receiving completion judging module is used for acquiring the current received data length and determining whether the data receiving is completed or not according to the current received data length and the preset data length.
10. A storage medium storing a computer program which, when executed by one or more processors, is adapted to carry out the method of any one of claims 1-8.
CN202211091849.5A 2022-09-07 2022-09-07 Data transmission method, device and storage medium Pending CN116303151A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211091849.5A CN116303151A (en) 2022-09-07 2022-09-07 Data transmission method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211091849.5A CN116303151A (en) 2022-09-07 2022-09-07 Data transmission method, device and storage medium

Publications (1)

Publication Number Publication Date
CN116303151A true CN116303151A (en) 2023-06-23

Family

ID=86776702

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211091849.5A Pending CN116303151A (en) 2022-09-07 2022-09-07 Data transmission method, device and storage medium

Country Status (1)

Country Link
CN (1) CN116303151A (en)

Similar Documents

Publication Publication Date Title
US11010327B2 (en) I3C point to point
US9946677B2 (en) Managing single-wire communications
EP3008610B1 (en) Camera control interface extension bus
JP2018517987A (en) Test for 50 nanosecond spike filter
US20170104607A1 (en) Methods to avoid i2c void message in i3c
US10572438B1 (en) Dynamic optimal data sampling time on a multi-drop bus
US20190171609A1 (en) Non-destructive outside device alerts for multi-lane i3c
US20200201804A1 (en) I3c device timing adjustment to accelerate in-band interrupts
CN111490947A (en) Data packet transmitting method, data packet receiving method, system, device and medium
CN112148322A (en) Method for upgrading firmware in single chip microcomputer connected with system on chip
WO2022089313A1 (en) Communication processing method and apparatus, storage medium, chip and related device
EP2658304A1 (en) Setting an Optimal Ping Interval
US10169281B2 (en) Switch system and operation method thereof
CN116303151A (en) Data transmission method, device and storage medium
WO2005076144A2 (en) Electronic device and methods of implementing the 1-wire protocol using an interrupt
CN104850203A (en) Electronic apparatus reset method and electronic apparatus
KR20210040780A (en) System and method for a user equipment to process overlapping physical downlink shared channels
CN109189705B (en) USB extension method, device, equipment, storage medium and system
CN112822226B (en) Data transmission method and device, electronic equipment and machine-readable storage medium
CN113268443A (en) SMI bus communication method, device, electronic equipment and medium
US20190223238A1 (en) Communication device and non-transitory computer-readable recording medium storing computer-readable instructions for communication device
CN115599722B (en) Method and device for realizing accurate transmission of serial port data based on kernel of operating system
CN115422117A (en) Low-cost reliable communication method between chips
CN111064488B (en) Transmitting/receiving device, transmitting/receiving system, storage medium, and transmitting/receiving method
CN117520243A (en) Method, device, equipment and medium for embedded UART serial double-line communication

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination