Communication baud rate identification system of electric energy meter
The baud rate of UART data is automatically identified through the SPI host, which solves the inconvenience and inefficiency caused by inconsistent baud rate during the reading of the power meter, and realizes the efficient and convenient reading of the power meter.
Patent Information
- Application Number
- CN202510643431.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2045-05-19
AI Technical Summary
When the baud rate of existing electricity meter is inconsistent, the meter reading equipment needs to manually try different baud rates to match the electricity meter, which leads to inconvenient and inefficient meter reading process.
The SPI host is used instead of the UART slave to receive data, and the baud rate of the UART data is automatically recognized through the SPI host, and the clock frequency of the SPI host is an integer multiple of the highest baud rate of the UART host, and the baud rate is automatically recognized and matched.
It improves the convenience and accuracy of reading electricity meter, reduces manual intervention, and improves communication efficiency.
Smart Images

Figure CN120475281A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic electric energy meters, and in particular to a communication baud rate identification system for electric energy meters. Background Art
[0002] With the rapid development of my country's economy, the demand for electricity is increasing across all industries. Electricity meters are widely used in apartments, homes, office buildings, shopping malls, supermarkets, and other places. They are mainly used to measure energy consumption, monitor power system load, calculate electricity costs, and optimize power system operating efficiency.
[0003] The control unit in the energy meter is equipped with a Universal Asynchronous Receiver and Transmitter (UART) function. UART is a commonly used serial communication interface. The characteristic of UART output is that the UART host and slave each have a clock. The host transmits data at the transition edge of the clock pulse according to its own clock frequency. As a slave, the energy meter needs to receive data at its own clock frequency. When the baud rate of both parties is consistent, the clock pulse frequency is also consistent, then the data transmitted by the host can be received correctly and in a timely manner by the slave.
[0004] However, in actual use, external meter-reading equipment knows nothing about the meter's baud rate, other than the fixed 8 data bits, even parity, and 1 stop bit. If the baud rates of the meter and external meter-reading equipment are inconsistent—that is, the external meter-reading equipment transmits at its own clock frequency, while the meter receives at its own clock frequency—if the reception frequency is too fast, a single bit of data may be received multiple times. If the reception frequency is too slow, data may be missed. In either case, the start bit, parity bit, stop bit, and idle bit may be misinterpreted as data bits, resulting in garbled data.
[0005] Therefore, to avoid garbled data in meter readings, the current common practice is for external meter reading devices to manually send data at each baud rate, trial and error, until they find the right baud rate. If the meter doesn't respond to data sent by the external meter reading device, the device will delay and try again at a different baud rate. Only when the baud rate matches the meter's can the meter correctly receive and respond. This method is inconvenient and inefficient during meter reading. Summary of the Invention
[0006] In view of this, the present invention provides a communication baud rate identification system for an electric energy meter to solve the problem that the appropriate baud rate is manually tried and tested to send data to the electric energy meter, resulting in inconvenience in use and low meter reading efficiency during the meter reading process.
[0007] In a first aspect, the present invention provides a communication baud rate identification system for an electric energy meter, comprising: an asynchronous transceiver UART host, an SPI host, and a UART slave, wherein an interrupt pin and a receive pin of the SPI host are connected to the UART host via a communication interface, and a transmit pin and a clock pin of the SPI host are both left floating;
[0008] The SPI host's transmit pin is used to send detection data on the rising edge of each SPI clock pulse when the SPI host is turned on;
[0009] The SPI host's receive pin is used to receive UART data sent by the UART host on the falling edge of each SPI clock pulse when the SPI host is turned on;
[0010] The clock pin of the SPI host is used to set the clock frequency of the SPI host. The clock frequency is N times the highest baud rate of the UART host, where N≧2.
[0011] The interrupt pin is used to detect the change status of UART data in real time when the UART host sending line is idle. When it is detected that the UART data changes from high level to low level, an interrupt signal is generated to open the SPI host;
[0012] The SPI master is used to assume the baud rate to be tested of the UART master and continuously receive UART data through the receive pin of the SPI master each time the SPI master is in the open state, and the baud rate to be tested is less than or equal to the maximum baud rate of the UART master;
[0013] The SPI host is also used to determine that the baud rate to be measured is assumed to be correct when the UART data is recognized to be correct, and to re-assume the baud rate to be measured when the UART data is determined to be incorrectly recognized until the baud rate to be measured is recognized to be correct;
[0014] The UART slave device is used to return response data to the UART host when determining that the baud rate to be measured is correct, so that the UART host can send UART data according to the baud rate to be measured.
[0015] The present invention replaces the UART slave's reception with the SPI host's reception, i.e., the UART host sends data and the SPI host receives data. The SPI host receives and automatically identifies UART data at various baud rates. By having the SPI host pre-assume the baud rate to be tested for the UART host, there is no need to manually test different baud rates using external equipment, ultimately improving communication efficiency and enhancing the convenience and accuracy of electricity meter reading.
[0016] In some optional embodiments, the SPI host includes:
[0017] The receiving unit is used to continuously receive UART data through the receiving pin of the SPI host when the SPI host is turned on;
[0018] The storage unit is used to store UART data according to a preset data amount each time the SPI host is in an open state.
[0019] The present invention can obtain UART data of a preset data volume through the above method.
[0020] In some optional implementations, the SPI host further includes:
[0021] The calculation unit is used to calculate the target data volume of the continuously received UART data according to the preset data volume, the baud rate to be measured and the clock frequency.
[0022] The present invention is conducive to calculating the UART data of the target data volume through the calculation unit.
[0023] In some optional implementations, the SPI host further includes:
[0024] The detection unit is used to shut down the SPI host each time when the SPI host is in an open state and continuously receives the UART data of the target data amount. Once the UART data is idle data, the SPI host is turned off. When the UART data of the target data amount is not received, the UART data is continued to be received through the receiving unit.
[0025] The present invention facilitates real-time reception of UART data through the detection unit and can also save power consumption of the SPI host.
[0026] In some optional implementations, the SPI host further includes:
[0027] The assumption unit is used to assume the baud rate to be tested according to different levels of standard baud rates.
[0028] The present invention assumes the baud rate to be measured in the SPI host, and does not require manual repeated attempts to match various baud rates, which is beneficial to improving the baud rate recognition efficiency.
[0029] In some optional implementations, the SPI host further includes:
[0030] The extraction unit is used to extract UART data of a preset data volume from a preset position in the storage unit according to a preset interval.
[0031] The present invention extracts UART data in sequence through an extraction unit, which is beneficial to accurately identifying the baud rate to be measured.
[0032] In some optional embodiments, the preset data amount of UART data includes: a start bit, a data bit, an even parity bit, and a stop bit;
[0033] SPI master, also includes:
[0034] The first identification unit is used to identify whether the UART data of the start bit is correct, and if so, obtain the UART data of the even parity bit; if not, re-assume the baud rate to be measured through the assumption unit;
[0035] The second identification unit is used to identify whether the UART data of the even parity bit is correct when the UART data of the start bit is correct. If so, obtain the UART data of the stop bit. If not, re-assume the baud rate to be measured through the assumption unit;
[0036] The third identification unit is used to identify whether the UART data of the stop bit is correct when the UART data of the even parity bit is identified to be correct. If so, obtain the UART data of the data bit; if not, re-assume the baud rate to be measured through the assumption unit;
[0037] The data parsing unit is used to parse the UART data of the data bit according to the preset communication protocol when the UART data of the stop bit is identified to be correct.
[0038] The present invention is conducive to accurately identifying UART data of a preset data volume through the above method.
[0039] In some optional implementations, the SPI host further includes:
[0040] a fourth identification unit, configured to identify, based on the UART data of the data bit, whether the first frame header of the UART data of the data bit is correct; if so, obtain the current communication address of the UART data of the data bit; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified;
[0041] a fifth identification unit, configured to, when the first frame header of the UART data of the data bit is identified to be correct, identify whether the current communication address of the UART data of the data bit is correct, and if so, obtain the second frame header of the UART data; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is identified to be correct;
[0042] a sixth identification unit, configured to, when the current communication address of the UART data of the identified data bit is correct, identify whether the second frame header of the UART data is correct; if so, obtain the control code of the UART data; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified;
[0043] a seventh identification unit, configured to, when identifying that the second frame header of the UART data is correct, identify whether the data field length of the UART data is correct, and if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified;
[0044] an eighth identification unit, configured to, when it is determined that the length of the data field of the UART data is correct, identify whether the check code of the UART data is correct, and if so, obtain the end character of the UART data; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified;
[0045] The ninth identification unit is used to identify whether the end character of the UART data is correct when the check codes of the UART data are all correct. If so, it is determined that the baud rate to be measured is assumed to be correct. If not, the baud rate to be measured is re-assumed by the assumption unit until the baud rate to be measured is identified to be correct.
[0046] The present invention, through the above-mentioned implementation manner, is conducive to accurately identifying the meter reading data of the electric energy meter.
[0047] In some optional implementations, the SPI host further includes:
[0048] The interrupt pin is also used to generate an open signal when the UART slave successfully sends the response data, and re-detect the change status of the UART data in real time.
[0049] The present invention generates an on signal when the baud rate to be measured is successfully identified in the above manner, which is conducive to re-detecting the change state of UART data.
[0050] In some optional embodiments, the communication interface includes: a first communication interface and a second communication interface, the first communication interface and the UART host are provided in the external device;
[0051] The receiving pin of the UART host is connected to the output pin of the first communication interface, the sending pin of the UART host is connected to the input pin of the second communication interface, the output pin of the first communication interface is connected to the input pin of the second communication interface, and the input pin of the first communication interface is connected to the output pin of the second communication interface.
[0052] In some optional implementations, the further comprising: a UART slave, wherein the UART slave, the second communication interface, and the SPI master are arranged in the electric energy meter;
[0053] The sending pin of the UART slave is connected to the input pin of the second communication interface, the interrupt pin is connected to the output pin of the second communication interface, and the receiving pin of the UART slave is suspended. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0055] Figure 1 is a schematic diagram of a traditional electric energy meter communication structure according to an embodiment of the present invention;
[0056] Figure 2 is a schematic diagram of the communication structure of an improved electric energy meter according to an embodiment of the present invention;
[0057] Figure 3 1 is a schematic diagram of the data receiving timing of the SPI host according to an embodiment of the present invention;
[0058] Figure 4 Schematic diagram of the structure of the SPI host according to an embodiment of the present invention
[0059] Figure 5 is a schematic diagram of the DL / T645-2007 protocol format according to an embodiment of the present invention;
[0060] Figure 6 It is a schematic diagram of the flow of the SPI host executing data reception and analysis according to an embodiment of the present invention. DETAILED DESCRIPTION
[0061] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.
[0062] According to an embodiment of the present invention, an embodiment of a communication baud rate identification system for an electric energy meter is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0063] like Figure 1 As shown in FIG, a conventional electric energy meter communication structure diagram is shown, where a UART slave 11 is connected to a UART host 12 of an external device, wherein the UART slave 11 is deployed in the electric energy meter. Figure 1 In the example, since the MCU controller of the energy meter includes a UART slave 11, the MCU of the energy meter has its own UART data transmission and receiving function. The data output RO pin of the first communication interface 13 of the external device is connected to the receive pin RXD of the UART host 12, the data input pin DI of the first communication interface 13 is connected to the transmit pin TXD of the UART host 12, the data input pin DI of the second communication interface 14 is connected to the transmit pin TXD of the UART slave 12, and the data output pin RO of the second communication interface 14 is connected to the receive pin RXD of the UART slave 11. Only when the baud rate of the external device and the energy meter is consistent can the UART host 12 and the UART slave 11 communicate normally. That is, the external device sends UART data through the first communication interface 13, the RXD pin of the UART slave 11 can correctly receive and identify it, and then send response data through the TXD pin of the UART slave 11.
[0064] exist Figure 1 In the embodiment, when the baud rates of the external device and the electric energy meter are inconsistent, the UART host 12 sends UART data according to its own clock frequency, and the UART slave 11 receives UART data according to its own clock frequency, and automatically removes the start bit, stop bit, check bit and idle bit. The extracted 8-bit data bits may be a string of garbled codes, which will cause the UART slave 11 to be unable to correctly receive and identify the UART data sent by the UART host 12.
[0065] Furthermore, to avoid garbled data in meter readings, a common practice is to manually send data at each baud rate, trial and error, until a suitable baud rate is found. If the meter receives no response from the external meter reading device, the user will try a different baud rate after a delay. Only when the baud rate matches the meter's can the meter correctly receive and respond. This method is inconvenient and inefficient during meter reading.
[0066] The data transmission principle between an SPI master and an SPI slave is as follows: the master transmits data and receives data simultaneously. The SPI master has an SPI clock, while the slave does not. The master's clock output line is connected to the slave's clock input line, and both devices share a common clock. Because UART transmission uses its own clocks, which can deviate between them, the clock frequency cannot be very high. SPI transmission uses a common clock, which has no deviation and can be much higher than the UART clock frequency. SPI data has no idle bits, start bits, parity bits, or stop bits; it only has data bits, and all data is considered data. The SPI master transmits data to the SPI slave on each rising edge of the clock, and the SPI slave transmits data to the SPI master on each falling edge of the clock. Each byte of data is received after receiving 8 bits. When the master stops transmitting data, the clock pulses stop, and data transmission ceases.
[0067] Due to the differences in data transmission between UART hosts and SPI hosts, communication normally requires a UART host to communicate with a UART slave, and an SPI host to communicate with an SPI slave. However, the disclosed embodiments provide a communication baud rate identification system for an electricity meter. Leveraging the transmission characteristics of SPI and UART hosts, an SPI host is designed to receive data instead of a UART slave. Specifically, the UART host sends data, and the SPI host receives data. The SPI host receives and automatically identifies UART data at various baud rates. Ultimately, the disclosed embodiments improve communication efficiency and enhance the convenience and accuracy of electricity meter reading.
[0068] like Figure 2 As shown, the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure includes: an asynchronous transmitting and receiving UART host 12, an SPI host 15 and a UART slave 11, the interrupt pin 16 and the receiving pin of the SPI host 15 are connected to the UART host 12 through the communication interface, and the sending pin and the clock pin of the SPI host 15 are both suspended.
[0069] exist Figure 2 In the embodiment, the interrupt pin 16 is IO, the receiving pin of the SPI host 15 is MISO, the transmitting pin of the SPI host 15 is MOSI, and the clock pin of the SPI host 15 is SCLK.
[0070] exist Figure 2 In the embodiment, the sending pin MOSI of the SPI host 15 is used to send detection data at the rising edge of each SPI clock pulse when the SPI host 15 is turned on.
[0071] Specifically, after the SPI master function is turned on, the clock pulse starts working. At the rising edge of each SPI clock pulse, in order to ensure the continuity of the clock, invalid detection data is sent through the floating SPI master send pin MOSI.
[0072] exist Figure 2 In the embodiment, the receiving pin MISO of the SPI host 15 is used to receive the UART data sent by the UART host 12 at the falling edge of each SPI clock pulse when the SPI host 15 is turned on.
[0073] Specifically, after the SPI master function is enabled, the SPI master's receiving pin MISO automatically receives the UART data on the pin at the falling edge of each clock pulse. The UART data is level data.
[0074] exist Figure 2 In the embodiment, the clock pin SCLK of the SPI host 15 is used to set the clock frequency of the SPI host 15. The clock frequency is N times the highest baud rate of the UART host 12, where N≧2.
[0075] Common baud rates used in energy meters are 600, 1200, 2400, 4800, 9600, 19200, 38400, and 115200 (measured in bits per second). Set the SPI host's clock frequency to N times the UART host's maximum baud rate. For example, if the SPI host's clock frequency is an integer multiple of the UART host's maximum baud rate of 115200, the SPI host can fully detect all level changes on the receive pin, regardless of the baud rate sent by the UART host.
[0076] exist Figure 2 In the embodiment, the interrupt pin 16 is used to detect the change state of the UART data in real time when the UART host 12 sends an idle line. When it is detected that the UART data changes from a high level to a low level, an interrupt signal is generated to open the SPI host 15.
[0077] Specifically, the SPI master is shut down when it is idle. To save power, the SPI master is shut down. Interrupt pin IO detection is used, which monitors the level of the receive pin in real time. When the receive pin changes from high to low, it indicates that the UART master has begun transmitting the start bit. During the interrupt, the SPI master is turned on. To avoid frequent interrupts during transmission that affect the SPI master's execution efficiency, external interrupts are first disabled.
[0078] exist Figure 2In the embodiment, the SPI host 15 is used to assume that the baud rate to be measured of the UART host 12 and each time the SPI host is in an open state, the UART data is continuously received through the receiving pin of the SPI host 15, and the baud rate to be measured is less than or equal to the maximum baud rate of the UART host.
[0079] Specifically, because the baud rates of energy meters vary, normally, for an external device to exchange data with an energy meter, the communication formats of both parties must be identical. However, if the baud rates of the two communicating parties are inconsistent, the external device transmits at its own clock frequency, and the energy meter receives at its own clock frequency. If the reception frequency is too fast, a single bit of transmitted data may be received multiple times. If the reception frequency is too slow, data may be missed, resulting in garbled data.
[0080] Therefore, the disclosed embodiment uses the SPI host to pre-determine the baud rate of the UART host to be tested, eliminating the need to manually test different baud rates using external devices. Because the SPI host is part of the MCU controller within the energy meter, the baud rate to be tested is automatically adjusted within the MCU controller, thereby improving communication efficiency and enhancing the convenience and accuracy of meter reading.
[0081] For example, since the baud rate of 1152000 is an integer multiple of the baud rates of 600, 1200, 2400, 4800, 9600, 19200, 38400, and 115200, let's assume that the baud rate to be measured on the SPI host's receive pin MISO is 115200, N = 10, and the clock frequency is 10 times the baud rate. At this time, regardless of the baud rate at which the UART host continuously sends UART data, the SPI host can completely scan all level changes on the receive pin MISO. In the embodiments of the present disclosure, the baud rate to be measured is less than or equal to 115200. The baud rate to be measured can be any of the baud rates in the above examples and is not limited to 115200.
[0082] exist Figure 2 In the embodiment, the SPI host 15 is further configured to determine that the baud rate to be measured is assumed to be correct when the UART data is recognized to be correct, and to re-assume the baud rate to be measured when the UART data is determined to be recognized to be incorrect, until the baud rate to be measured is recognized to be correct.
[0083] exist Figure 2 In the embodiment, the UART slave 11 is used to return response data to the UART host 12 when determining that the baud rate to be measured is correct, so that the UART host 12 sends UART data according to the baud rate to be measured.
[0084] In a specific example, the preset data amount of UART data includes: a start bit, a data bit, an even parity bit, and a stop bit.
[0085] Specifically, the preset data amount can be 1 byte of data. The principle of the SPI host receiving 1 byte of data is as follows: UART data is received on a single line with a width of 1 bit. 1 byte of data has 11 bits, namely 1 start bit, 8 data bits, 1 check bit, and 1 stop bit. These 11 bits of UART data are received one by one in sequence on the transition edge of the SPI clock.
[0086] When the SPI host is idle, the level on the SPI host's receiving pin MISO is high. The UART host has a built-in clock. Different baud rates correspond to different clock frequencies. The level on the SPI host's receiving pin MISO is captured in real time at the transition edge of the clock pulse to see whether it changes from high to low.
[0087] The 1-bit start bit is fixed at a low level. When the edge transition of the clock pulse is detected from a high level to a low level, it is considered that the start bit is received, and then the data bit is received.
[0088] The 8 data bits are the actual content to be transmitted. At each clock pulse transition edge, the 8 data bits are received one by one in sequence, followed by the even parity bit.
[0089] 1-bit even parity bit: The even parity bit is received at the transition edge of the clock pulse.
[0090] One stop bit is fixed at high level and is received when the edge of the clock pulse changes.
[0091] When the SPI host is identifying UART data, the data received by the SPI host is stored byte by byte. When the SPI host receives several bytes of UART data continuously, that is, it receives idle bits all the time, it considers that the reception of all data is completed.
[0092] In a specific example, if the communication baud rates between the UART master and the SPI slave do not match, the data received by the SPI master appears to be garbled. The SPI master must extract 8 data bits from the 11-bit UART format, one by one, from the beginning to the end. The SPI master first assumes a certain baud rate to be tested and, based on the relationship between the clock frequency and multiples of this baud rate, determines whether the 11 bits of UART data are correct. If all 11 bits of UART data are correctly identified, the assumed baud rate is correct. If any of the 11 bits of UART data are incorrectly identified, the UART data is incorrectly identified. If this identification is correct, the UART master sent the UART data at the assumed baud rate to be tested. The UART slave then returns response data to the UART master, informing the UART master that it can use the assumed baud rate to be tested. If this identification is incorrect, the UART master did not send the UART data at that baud rate. Another baud rate to be tested is then assumed, and the identification process is repeated until the correct baud rate is identified.
[0093] Therefore, in the communication baud rate identification system for an energy meter in the disclosed embodiment, the SPI host receives data instead of the UART slave, i.e., the UART host sends data and the SPI host receives data. The SPI host receives and automatically identifies UART data at various baud rates. By having the SPI host presume the baud rate to be tested for the UART host, there is no need to manually test different baud rates using external devices. This ultimately improves communication efficiency and enhances the convenience and accuracy of energy meter reading.
[0094] In some specific embodiments, such as Figure 4 As shown, in the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure, the SPI host 15 includes: a receiving unit 151, a storage unit 152, a calculation unit 153, a detection unit 154, an assumption unit 155 and an extraction unit 156.
[0095] exist Figure 4 In the embodiment, the receiving unit 151 is used to continuously receive UART data through the receiving pin of the SPI host 15.
[0096] exist Figure 4 In the embodiment, the storage unit 152 is used to store UART data according to a preset data amount each time the SPI host 15 is in an open state.
[0097] Specifically, the preset amount is 1 byte of data, usually 11 bits of UART data. In the example above, the preset amount of UART data includes: a start bit, a data bit, an even parity bit, and a stop bit.
[0098] Because the SPI clock frequency is an integer multiple of the UART's maximum baud rate of 115200, the SPI master can fully detect all voltage level changes on its receive pin, regardless of the baud rate sent by the external device, including the start bit, data bits, parity bit, and stop bit transmitted by the UART master. After receiving each 8-bit byte, the storage unit stores the 8 bits of UART data. For example, the storage unit can store a preset amount of UART data in a table.
[0099] exist Figure 4 In the embodiment, the calculation unit 153 is used to calculate the target data volume of the continuously received UART data according to the preset data volume, the baud rate to be measured and the clock frequency.
[0100] For example, assuming the baud rate to be measured is 600, based on the minimum baud rate to be measured of 600, the clock frequency is set to N times the maximum baud rate of the UART host, 115200. Assuming N is 10, the clock frequency is 1152000, and the preset data size is 11 bits. The target data size is represented by M, M = 11 * 1152000 / 600.
[0101] exist Figure 4 In the embodiment, the detection unit 154 is used to shut down the SPI host 15 when the SPI host 15 is in the open state and continuously receives the UART data of the target data amount. Once it is detected that the UART data is idle data, the SPI host 15 is turned off. When the UART data of the target data amount is not received, the UART data is continued to be received through the receiving unit 151.
[0102] For example, if the SPI host receives 11*1152000 / 600 data FFs in succession, once it detects that the UART data is idle, it considers that the data reception is completed and shuts down the SPI host. After processing the data in the storage unit table, it will start the next round of data reception and reopen the SPI host.
[0103] exist Figure 4 In the embodiment, the assuming unit 155 is used to assume the baud rate to be measured according to different levels of standard baud rates.
[0104] Since the commonly used baud rates are 600, 1200, 2400, 4800, 9600, 19200, 38400, and 115200, and the unit is bps, the baud rate to be tested can be assumed by assuming the unit according to the standard baud rates of different levels.
[0105] exist Figure 4 In the embodiment, the extraction unit 156 is configured to extract a preset amount of UART data from the storage unit 152 starting from a preset position and at a preset interval.
[0106] Specifically, a UART host sends a byte of data, which is 11 bits. For example, using the DL / T645-2007 communication protocol, a SPI host receives an 8-bit byte. The received data appears to be a string of garbled characters, mixed with a start bit, 8 data bits, an even parity bit, a stop bit, and several idle bits. The only useful bits are the 8 data bits. The 8 data bits must be extracted one by one from the beginning to the end, following the UART format. At this point, the SPI host does not know the baud rate of the data on its receive pin. It first assumes a certain baud rate and, based on the relationship between the clock frequency and multiples of that baud rate, extracts the start bit, 8 data bits, 1 parity bit, and 1 stop bit at intervals corresponding to the multiples. After extracting one byte of data, it searches one bit at a time for the start bit of the next byte. If a 0 is found, it is considered the start bit. The start bit, 8 data bits, 1 parity bit, and 1 stop bit are then extracted at intervals corresponding to the multiples until all the data has been extracted.
[0107] Specifically, since the clock frequency 1152000 is an integer multiple of the baud rates 600, 1200, 2400, 4800, 9600, 19200, 38400, and 115200, it is first assumed that the baud rate to be measured of the receiving pin is 115200 and the clock frequency is 10 times the baud rate. In order to make the collected data more reliable, data is extracted at the preset position of each data bit UART transmission, and the preset position can be the middle position.
[0108] For example, Figure 3 As shown, the data in the table are arranged bit by bit. From the front to the back, the 5th bit is extracted as the start bit, the 15th, 25th, 35th, 45th, 55th, 65th, 75th, and 85th bits are 8 data bits, the 95th bit is the even parity bit, and the 105th bit is the stop bit. After the stop bit ends, the extraction of an 11-bit byte of UART data is completed. There may be several idle bits between this byte and the next byte. Starting from the 105th bit, search for the start bit of the next byte one by one. When the 105th bit is found, the start bit of the next byte is searched. After 05+X, if 0 is found, it is considered to be the start bit of the next byte. Bits 110+X are extracted as the start bit. Bits 120+X, 130+X, 140+X, 150+X, 160+X, 170+X, 180+X, and 190+X are 8 data bits. Bit 200+X is the even parity bit, and bit 210+X is the stop bit. After the stop bit, the extraction of another byte is completed, and the next byte of UART data is extracted according to the above example.
[0109] In a more specific embodiment, the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure is Figure 4In the embodiment, the SPI host 15 further includes: a first identification unit 1570, a second identification unit 1571, a third identification unit 1572, a data parsing unit 1573, a fourth identification unit 1574, a fifth identification unit 1575, a sixth identification unit 1576, a seventh identification unit 1577, an eighth identification unit 1578, and a ninth identification unit 1579.
[0110] exist Figure 4 In the embodiment, the first identification unit 1570 is used to identify whether the UART data of the start bit is correct. If so, the UART data of the even parity bit is obtained. If not, the baud rate to be measured is re-assumed through the assumption unit 155.
[0111] Because the start bit is fixed at a low level, when the first recognition unit detects that the start bit received by the SPI host's receive pin changes from a high level to a low level at the transition edge of the clock pulse, it indicates that the UART data of the start bit has been correctly recognized. Otherwise, it indicates that the recognition is incorrect. In this case, the baud rate to be tested is re-assumed using the assumption unit in the above example. If the first recognition unit recognizes incorrectly, it means that the external device is not transmitting data at the pre-assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0112] exist Figure 4 In the embodiment, the second identification unit 1571 is used to identify whether the UART data of the even parity bit is correct when the UART data of the start bit is correct. If so, the UART data of the stop bit is obtained. If not, the baud rate to be measured is re-assumed through the assumption unit 155.
[0113] If the first identification unit correctly identifies the data, and the second identification unit detects that the number of high levels of the even parity bit received by the SPI host's receive pin during the transition edge of the clock pulse is an even number, then the UART data for the even parity bit is correctly identified. In this case, the UART data for the stop bit is obtained. Otherwise, the identification is incorrect. In this case, the baud rate to be tested is re-assumed using the assumption unit described in the above example. If the second identification unit incorrectly identifies the data, then another baud rate to be tested is re-assumed.
[0114] exist Figure 4 In the embodiment, the third identification unit 1572 is used to identify whether the UART data of the stop bit is correct when the UART data of the even parity bit is correct. If so, the UART data of the data bit is obtained. If not, the baud rate to be measured is re-assumed through the assumption unit.
[0115] If the second recognition unit correctly identifies the stop bit, since it is fixed at a high level, the third recognition unit recognizes that the stop bit received by the SPI host's receive pin changes from a low level to a high level during the clock pulse transition, indicating that the UART data of the stop bit has been correctly identified. At this time, the UART data of the data bit is obtained. Otherwise, it indicates that the identification is incorrect. At this time, the baud rate to be tested is re-assumed using the assumption unit in the above example. If the third recognition unit incorrectly identifies the external device, it indicates that the external device is not transmitting data at the pre-assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0116] exist Figure 4 In the embodiment, the data parsing unit 1573 is used to parse the UART data of the data bit according to the preset communication protocol when the UART data of the stop bit is identified to be correct.
[0117] In a specific example, the preset communication protocol is the DL / T645-2007 protocol.
[0118] The DL / T645-2007 protocol is a widely used communication protocol. Typically, an energy meter acts as a slave. External devices can read meter data or set meter parameters using the DL / T645-2007 protocol through the 485 communication port. The meter then takes action or responds upon receiving the data. The DL / T645-2007 protocol format includes the baud rate, data bits, parity bit, and stop bit. The data bits are fixed at 8, the parity bit is fixed at even, and the stop bit is fixed at 1.
[0119] On the premise that the start bit, even parity bit and stop bit are correctly identified, the data parsing unit parses the data on the 8 data bits extracted by the extraction unit according to the DL / T645-2007 protocol.
[0120] exist Figure 4 In the embodiment, the fourth identification unit 1574 is used to identify whether the first frame header of the UART data of the data bit is correct based on the UART data of the data bit. If so, the current communication address of the UART data of the data bit is obtained; if not, the baud rate to be tested is re-assumed through the assumption unit until the baud rate to be tested is correctly identified.
[0121] When the UART data of the data bit parsed by the above data parsing unit is correct, since the data format of the DL / T645-2007 protocol is as follows Figure 5As shown. The fourth recognition unit first determines whether 68H of the first frame header is correct. If the first frame header is correctly recognized, it obtains the current communication address of the UART data of the data bit. This current communication address is 6 bytes, namely A0A1A2A3A4A5A6. Otherwise, it indicates a recognition error. In this case, the assumption unit of the above example re-assumes the baud rate to be tested. If the fourth recognition unit recognizes incorrectly, it means that the external device is not transmitting data at the pre-assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0122] exist Figure 4 In the embodiment, the fifth identification unit 1575 is used to identify whether the current communication address of the UART data of the data bit is correct when the first frame header of the UART data of the data bit is correctly identified. If so, the second frame header of the UART data is obtained; if not, the baud rate to be measured is re-assumed through the assumption unit until the baud rate to be measured is correctly identified.
[0123] The fifth identification unit is mainly used to identify Figure 5 The 6-byte current communication address A0A1A2A3A4A5A6 in the identification process is correct. In the specific identification process, the current communication address is matched with the preset communication address. If the match is successful, it means that the identification is correct. Under the premise of correct identification, 68H of the second frame header is obtained. If the match is incorrect, the baud rate to be tested is re-assumed through the assumption unit in the above example. If the fifth identification unit recognizes incorrectly, it means that the external device is not transmitting data at the pre-assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0124] exist Figure 4 In the embodiment, the sixth identification unit 1576 is used to identify whether the second frame header of the UART data is correct when the current communication address of the UART data of the identified data bit is correct. If so, the control code of the UART data is obtained. If not, the baud rate to be measured is re-assumed through the assumption unit until the baud rate to be measured is correctly identified.
[0125] If the fifth identification unit correctly identifies the data, the sixth identification unit identifies whether the 68H in the second frame header is correct. If the identification is correct, the control code of the UART data is obtained, which can be represented by C. If the identification is incorrect, the baud rate to be tested is re-assumed using the assumption unit in the above example. If the sixth identification unit incorrectly identifies the data, it means that the external device is not transmitting data at the previously assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0126] exist Figure 4In the embodiment, the seventh identification unit 1577 is used to identify whether the data field length of the UART data is correct when the second frame header of the UART data is identified correctly. If not, the baud rate to be measured is re-assumed through the assumption unit until the baud rate to be measured is identified correctly.
[0127] exist Figure 5 In the example, the data field lengths of the UART data are N1...Nm, respectively, and the data field length is L. The seventh identification unit identifies whether the data field length L is correct. If the identification is incorrect, the baud rate to be tested is re-assumed using the assumption unit described in the above example. If the seventh identification unit identifies an error, it indicates that the external device is not transmitting data at the previously assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0128] exist Figure 4 In the embodiment, the eighth identification unit 1578 is used to identify whether the check code of the UART data is correct when the data field length of the UART data is correct. If so, the end mark of the UART data is obtained; if not, the baud rate to be measured is re-assumed through the assumption unit until the baud rate to be measured is correctly identified.
[0129] If the seventh identification unit correctly identifies the UART data, the eighth identification unit then identifies whether the checksum of the UART data is correct. If the identification is correct, the end character of the UART data is obtained. If the identification is incorrect, the baud rate to be tested is re-assumed using the assumption unit described in the above example. If the eighth identification unit incorrectly identifies the external device, it indicates that the external device is not transmitting data at the previously assumed baud rate to be tested, and another baud rate to be tested is re-assumed.
[0130] exist Figure 4 In the embodiment, the ninth identification unit 1579 is used to identify whether the end character of the UART data is correct when the check code of the UART data is correct. If so, it is determined that the baud rate to be measured is assumed to be correct. If not, the baud rate to be measured is re-assumed by the assumption unit until the baud rate to be measured is identified as correct.
[0131] If the eighth recognition unit correctly identifies the data, the ninth recognition unit identifies the terminator of the UART data, which is 16H. If the terminator is correctly identified, the baud rate assumption to be tested is determined to be correct, i.e., the external device is determined to be transmitting data at the pre-determined baud rate to be tested, and the UART host can be configured to use the pre-determined baud rate. If the identification is incorrect, it indicates that the identification is incorrect. In this case, the baud rate to be tested is re-assumed using the assumption unit in the above example. If the ninth recognition unit incorrectly identifies the data, it indicates that the external device is not transmitting data at the pre-determined baud rate to be tested, and another baud rate to be tested is re-assumed.
[0132] exist Figure 2In the embodiment, the interrupt pin 16 is also used to generate an open signal when the UART slave 11 successfully sends the response data, and re-detect the change status of the UART data in real time.
[0133] If the entire UART data frame conforms to the DL / T645-2007 protocol after identification, it indicates that the external device is sending data at the pre-tested baud rate. After configuring the UART master to the test baud rate, use the UART slave's built-in send function to respond with data. After the transmission is complete, enable the interrupt pin again to re-test the UART data.
[0134] like Figure 6 As shown, the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure is executed in sequence by the receiving unit, storage unit, calculation unit, detection unit, assumption unit, extraction unit, first identification unit, second identification unit, third identification unit, data parsing unit, fourth identification unit, fifth identification unit, sixth identification unit, seventh identification unit, eighth identification unit, and ninth identification unit in the above-mentioned example. The specific execution process is as follows:
[0135] Step 1: Enable interrupt detection on the SPI host's IO pin;
[0136] Step 2: Enable the SPI master during the interrupt and disable the interrupt;
[0137] Step 3: Determine whether the SPI host has received the data. If so, execute the following step 4. If not, execute the following step 5.
[0138] Step 4: Store the data in the table;
[0139] Step 5: Determine whether a number of data FFs are received continuously. If yes, execute the following step 6; if not, execute the above step 3.
[0140] Step 6: Turn off the SPI master;
[0141] Step 7: Assume one of the baud rates;
[0142] Step 8: Extract the start bit;
[0143] Step 9: Extract 8 data bits;
[0144] Step 10: Extract the even parity bit;
[0145] Step 11: Extract 1 stop bit;
[0146] Step 12: Determine whether the start position is correct; if so, execute the following step 13; if not, execute the above step 7;
[0147] Step 13: Determine whether the even parity bit is correct. If so, execute the following step 14. If not, execute the above step 7.
[0148] Step 14: Determine whether the stop position is correct. If so, execute the following step 14. If not, execute the above step 7.
[0149] Step 15: Determine whether the first frame header 68H is correct. If so, execute the following step 16. If not, execute the above step 7.
[0150] Step 16: Determine whether the mailing address is correct. If so, proceed to step 17 below. If not, proceed to step 7 above.
[0151] Step 17: Determine whether the second frame header 68H is correct. If so, execute the following step 18. If not, execute the above step 7.
[0152] Step 18: Determine whether the control code C is correct. If so, execute the following step 19. If not, execute the above step 7.
[0153] Step 19: Determine whether the length L is correct. If so, execute the following step 20. If not, execute the above step 7.
[0154] Step 20: Determine whether the check code CS is correct. If so, execute the following step 21; if not, execute the above step 7;
[0155] Step 21: Determine whether the end character 16H is correct. If so, execute the following step 22. If not, execute the above step 7.
[0156] Step 22: Identify the pre-assumed baud rate;
[0157] Step 23: Use the UART slave to send response data to the UART master;
[0158] Step 24: After the response is completed, enable IO interrupt detection.
[0159] In some specific embodiments, the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure, the communication interface includes: a first communication interface 13 and a second communication interface 14, the first communication interface 13 and the UART host 12 are set in an external device; the receiving pin of the UART host 12 is connected to the output pin of the first communication interface 13, the sending pin of the UART host is connected to the input pin of the second communication interface 14, the output pin of the first communication interface 13 is connected to the input pin of the second communication interface 14, and the input pin of the first communication interface 13 is connected to the output pin of the second communication interface 14.
[0160] That is to say Figure 2This is a diagram of the improved communication line connection for the electricity meter in the disclosed embodiment. The electricity meter's MCU has built-in SPI functionality. Because only an SPI master has a clock function, an SPI master is used instead of an SPI slave. The SPI master's receive pin, MISO, replaces the UART slave's receive pin, RXD. The original UART slave's receive pin, RXD, no longer receives data and is left floating. The 485 data output pin, RO, is connected to the SPI master's receive pin, MISO, and IO pins. The 485 data input pin, DI, is connected to the UART master's transmit pin, TX. The SPI master's clock pin, SCLK, is left floating, primarily to utilize the SPI master's clock pulse. Since there is no external SPI slave, this clock pin does not need to be connected externally. The SPI master's transmit pin, MOSI, is left floating, since there is no external SPI slave, this transmit pin does not need to be connected externally. However, the floating transmit pin needs to continuously transmit data during the data reception process to ensure that the clock pulse is continuous and uninterrupted, and data can be properly received on each falling edge of the clock pulse. If no data is transmitted, the clock stops. However, the data to be transmitted can be set arbitrarily.
[0161] In some specific implementations, the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure is Figure 2 The electric energy meter also includes: a UART slave 11, a second communication interface 14 and an SPI host 15 are arranged in the electric energy meter; the sending pin of the UART slave 11 is connected to the input pin of the second communication interface 14, the interrupt pin 16 and the sending pin of the SPI host 15 are connected to the output pin of the second communication interface 14, and the receiving pin of the UART slave 11 is left floating.
[0162] exist Figure 2 In the example, the interrupt pin IO is connected to the transmit pin MISO of the SPI master 15, and the output pin RO of the second communication interface is connected. Meanwhile, the receive pin of the UART master 12 is connected to the transmit pin of the UART slave 11. After recognition, the UART slave 11 sends a data response. The transmit pin and clock pin of the SPI master 15 are left floating, and the receive pin of the UART slave 11 is left floating.
[0163] Therefore, through the above examples, the communication baud rate identification system of the electric energy meter in the embodiment of the present disclosure can self-identify data sent by external devices at different baud rates and make correct responses without increasing the cost of the electric energy meter and only adding a small amount of system resources.
[0164] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A communication baud rate identification system for an electric energy meter, characterized in that: include: Asynchronous transceiver UART host, SPI host, UART slave and interrupt pin, the interrupt pin and the receive pin of the SPI host are connected to the UART host through a communication interface, and the send pin and clock pin of the SPI host are both suspended; The sending pin of the SPI host is used to send detection data on the rising edge of each SPI clock pulse when the SPI host is turned on; The receiving pin of the SPI host is used to receive UART data sent by the UART host at the falling edge of each SPI clock pulse when the SPI host is turned on; The clock pin of the SPI host is used to set the clock frequency of the SPI host, where the clock frequency is N times the highest baud rate of the UART host, where N≧2; The interrupt pin is used to detect the change state of the UART data in real time when the UART host sending line is idle. When it is detected that the UART data changes from a high level to a low level, an interrupt signal is generated to turn on the SPI host; The SPI host is configured to assume a baud rate to be measured of the UART host and continuously receive the UART data through a receive pin of the SPI host each time the SPI host is in an open state, wherein the baud rate to be measured is less than or equal to the maximum baud rate of the UART host; The SPI host is further configured to, when identifying that the UART data is correct, determine that the baud rate to be measured is assumed to be correct, and when determining that the UART data is incorrectly identified, re-assume the baud rate to be measured until the baud rate to be measured is identified to be correct; The UART slave is used to return response data to the UART host when determining that the baud rate to be measured is assumed to be correct, so that the UART host sends the UART data according to the baud rate to be measured.
2. The communication baud rate identification system of the electric energy meter according to claim 1, characterized in that: The SPI host comprises: a receiving unit, configured to continuously receive the UART data through a receiving pin of the SPI host when the SPI host is turned on; A storage unit is used to store the UART data according to a preset data amount each time the SPI host is in an open state.
3. The communication baud rate identification system of the electric energy meter according to claim 2, characterized in that: The SPI master includes: A calculation unit is used to calculate a target data volume of the UART data continuously received according to the preset data volume, the baud rate to be measured and the clock frequency.
4. The communication baud rate identification system of the electric energy meter according to claim 3, characterized in that: The SPI host further includes: The detection unit is configured to, when the SPI host is in an open state each time, after continuously receiving the UART data of the target data amount, shut down the SPI host once the UART data is idle data, and continue to receive the UART data through the receiving unit when the UART data of the target data amount is not received.
5. The communication baud rate identification system of the electric energy meter according to claim 3, characterized in that: The SPI host further includes: an assuming unit, configured to assume the baud rate to be measured according to standard baud rates of different levels; The extraction unit is used to extract the UART data of the preset data volume from the storage unit at a preset interval starting from a preset position.
6. The communication baud rate identification system of the electric energy meter according to claim 5, characterized in that: The UART data of the preset data amount includes: a start bit, a data bit, an even parity bit, and a stop bit; The SPI host further includes: a first identification unit, configured to identify whether the UART data of the start bit is correct, and if so, obtain the UART data of the even parity bit; and if not, re-assume the baud rate to be measured through the assumption unit; a second identification unit, configured to, when identifying that the UART data of the start bit is correct, identify whether the UART data of the even parity bit is correct; if so, obtain the UART data of the stop bit; if not, re-assume the baud rate to be measured through the assumption unit; a third identification unit, configured to, when identifying that the UART data of the even parity bit is correct, identify whether the UART data of the stop bit is correct; if so, obtain the UART data of the data bit; if not, re-assume the baud rate to be measured through the assumption unit; The data parsing unit is configured to parse the UART data of the data bit according to a preset communication protocol when it is identified that the UART data of the stop bit is correct.
7. The communication baud rate identification system of the electric energy meter according to claim 6, characterized in that: The SPI host further includes: a fourth identification unit, configured to identify, based on the UART data of the data bit, whether a first frame header of the UART data of the data bit is correct; if so, obtain a current communication address of the UART data of the data bit; if not, re-assume the baud rate to be measured by the assumption unit until the baud rate to be measured is identified as correct; a fifth identification unit, configured to, when identifying the first frame header of the UART data of the data bit as correct, further identify whether the current communication address of the UART data of the data bit is correct, and if so, obtain the second frame header of the UART data; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified; a sixth identification unit, configured to, when identifying the current communication address of the UART data of the data bit as correct, further identify whether the second frame header of the UART data is correct; if so, obtain the control code of the UART data; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified; a seventh identification unit, configured to, when identifying that the second frame header of the UART data is correct, identify whether the data field length of the UART data is correct, and if not, re-assume the baud rate to be measured by the assumption unit until the baud rate to be measured is correctly identified; an eighth identification unit, configured to, when it is determined that the data field length of the UART data is correct, identify whether the check code of the UART data is correct, and if so, obtain the end character of the UART data; if not, re-assume the baud rate to be measured through the assumption unit until the baud rate to be measured is correctly identified; The ninth identification unit is used to identify whether the end character of the UART data is correct when the check codes of the UART data are all correct. If so, it is determined that the baud rate to be measured is assumed to be correct. If not, the baud rate to be measured is re-assumed by the assumption unit until the baud rate to be measured is identified as correct.
8. The communication baud rate identification system for an electric energy meter according to any one of claims 1 to 7, characterized in that: The interrupt pin is also used to generate an open signal when the UART slave successfully sends the response data, and re-detect the change status of the UART data in real time.
9. The communication baud rate identification system of an electric energy meter according to claim 1, characterized in that: The communication interface includes: a first communication interface and a second communication interface, wherein the first communication interface and the UART host are arranged in an external device; The receiving pin of the UART host is connected to the output pin of the first communication interface, the sending pin of the UART host is connected to the input pin of the second communication interface, the output pin of the first communication interface is connected to the input pin of the second communication interface, and the input pin of the first communication interface is connected to the output pin of the second communication interface.
10. The communication baud rate identification system of the electric energy meter according to claim 9, characterized in that: Also includes: The UART slave, the second communication interface and the SPI host are arranged in an electric energy meter; The sending pin of the UART slave is connected to the input pin of the second communication interface, the interrupt pin and the sending pin of the SPI host are connected to the output pin of the second communication interface, and the receiving pin of the UART slave is suspended.