Disclosure of Invention
In order to solve the problems in the prior art, the invention provides a wireless communication device based on LoRa and a wireless communication method based on the wireless communication device.
The wireless communication device comprises an MCU and more than two LoRa radio frequency chips, wherein the LoRa radio frequency chips are connected in parallel on a bus connected with the MCU, the receiving and sending of the LoRa radio frequency chips adopt an interrupt mode, the receiving and sending interrupt pin of each LoRa radio frequency chip is respectively connected with the external interrupt pin of the MCU,
the MCU comprises a packet packaging module which is used for splitting data into data pieces according to the length of the data, distributing corresponding LoRa radio frequency chips for parallel transmission, and assembling the received data pieces into data according to a data protocol;
the LoRa radio frequency chip management module is used for initializing each hardware and managing the receiving and sending data of the LoRa radio frequency chip; and the channel management module is used for setting the channel and the frequency of two wireless communication devices which are communicated with each other.
The invention is further improved, and the MCU is provided with an SPI interface and/or a USB interface.
The invention is further improved, and the LoRa radio frequency chip is connected in parallel with the SPI interface end of the MCU through the SPI bus.
The invention is further improved, and the LoRa radio frequency chips are respectively connected in parallel with the USB bus connected with the USB interface of the MCU through the USB to SPI chips.
The invention is further improved, and the LoRa radio frequency chip is an sx127x series radio frequency chip of Semtech company.
The invention also provides a wireless communication method based on the wireless communication device, which comprises the steps of data transmission and data reception, wherein,
the processing method of the data sending step comprises the following steps:
a1: starting, the LoRa radio frequency chip management module initializes external interrupt, SPI or USB bus related to the MCU and the LoRa radio frequency chip, and GPIO pin of the LoRa radio frequency chip;
a2: initializing all LoRa radio frequency chip related registers, configuring interruption, configuring a transceiving buffer and configuring fixed transceiving frequency by a channel management module;
a3: waiting for data to be sent;
a4: starting to send data, fragmenting the data according to the length of the data by a packet packaging module, and writing the data fragments into sending caches of different LoRa radio frequency chips respectively;
a5: configuring a LoRa radio frequency chip to send an interrupt, and after the data sheet is sent, the interrupt occurs;
a6: judging whether data need to be sent at this time, if so, executing the step A4, and if not, executing the step A3, wherein the processing method of the data receiving step comprises the following steps:
b1: starting, the LoRa radio frequency chip management module initializes external interrupt, SPI or USB bus related to the MCU and the LoRa radio frequency chip, and GPIO pin of the LoRa radio frequency chip;
b2: initializing all LoRa radio frequency chip related registers, configuring interruption, configuring a transceiving buffer and configuring fixed transceiving frequency by a channel management module;
b3: waiting for a data reception interrupt;
b4: receiving interruption occurs to the LoRa radio frequency chip, and data reception is started;
b5: clearing the receiving interrupt;
b6: and the packet packaging module is used for packaging the received data slices according to a data protocol.
The invention is further improved, in step a4, the method for processing the packets of the packet packaging module comprises: and starting, judging whether the total length of the data is greater than n × M, wherein n is the number of LoRa radio frequency chips, M is the sending buffer size of the LoRa radio frequency chips, if yes, dividing the data according to the maximum length of each packet of data as M, if not, dividing the length of each packet of data according to the total length divided by n, and ending.
The invention is further improved, in step B6, the group packaging processing method of the group packaging module includes:
b61: reading the data received and cached by the LoRa radio frequency chip in sequence according to the interrupt sequence;
b62: analyzing data according to a data protocol, and arranging the data according to a packet sequence;
b63: all the data pieces are received, and the process is finished.
In a further refinement of the present invention, the data protocol format includes a total number of packets, a packet order, a data length, data, and a CRC.
Compared with the prior art, the invention has the beneficial effects that: the problem of low data transmission rate of the LoRa radio frequency chip is effectively solved; the sub-package and the packet package are fully optimized, so that the sending rate and the sending efficiency are greatly increased; the long-distance characteristic of the LoRa radio frequency chip sx127x is fully utilized, and a novel long-distance and medium-speed wireless communication method is generated.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples.
As shown in fig. 1 and 2, the wireless communication device of the present invention includes an MCU (micro control unit) and more than two LoRa rf chips, wherein the LoRa rf chips are connected in parallel to a bus connected to the MCU, the LoRa rf chips receive and transmit data in an interrupted manner, and the interrupt pins of each LoRa rf chip are connected to the external interrupt pins of the MCU.
The MCU of this example is provided with an SPI (serial peripheral interface) interface and/or a USB interface. As an embodiment of the present invention, the LoRa rf chips are connected in parallel to the SPI interface of the MCU through the SPI bus, all the LoRa rf chips are mounted on the SPI bus of the MCU, and the transmit/receive interrupt pins of the LoRa rf chips are all connected to the external interrupt pins of the MCU.
As another embodiment, the LoRa rf chips of this example are respectively connected in parallel to the USB bus connected to the USB interface of the MCU through the USB to SPI chips, and all the LoRa rf chips first convert the SPI interface into the USB interface through the USB to SPI chip, and then mount the LoRa rf chips on the USB bus, and connect the transmit/receive interrupt pins of the LoRa rf chips to the external interrupt pins of the MCU.
The LoRa rf chip in this example is preferably an sx127x series rf chip provided by Semtech for terminal node communication, and has a long transmission distance.
In the embodiment, a wireless communication method based on long distance (3-30km) and medium speed of LoRa is constructed by mainly improving hardware and software and adopting a plurality of LoRa radio frequency chips for concurrence, so that data concurrence is realized, the problem of low data rate of the LoRa radio frequency chip sx127x is effectively solved, and the data sending speed and efficiency are greatly improved.
In terms of software, the MCU in this embodiment includes a packetization module, a LoRa rf chip management module, and a channel management module. The invention is described in detail by taking an sx127x radio frequency chip as an example.
The sub-packet packaging module is used for splitting the data into data pieces according to the length of the data, distributing corresponding LoRa radio frequency chips to send the data pieces in parallel, and assembling the received data pieces into the data according to a data protocol. The sub-packaging mainly considers that when the length of data is smaller than the sum of the sending buffers of all the LoRa radio frequency chips sx127x, the mode of uniform distribution sending is adopted, and some LoRa radio frequency chips sx127x are not sent, and other sending is not sent, so that the sending is faster.
The LoRa radio frequency chip management module is mainly used for initializing, receiving and sending data of the hardware of the sx127x radio frequency chip. The hardware initialization mainly includes the MCU related SPI or USB bus, the MCU and the related interrupts of sx127 x. Receiving and sending data is primarily the operation sx127x associated cache and interrupt tag registers.
A channel management module: for setting the channel and frequency of two wireless communication devices communicating with each other. If communication is required between two devices, the same channel and frequency are required to be set, for example, the channel and frequency of the first sx127x of the device a and the first sx127x of the device B are the same, and the remaining sx127x is similar.
The example also provides a wireless communication method based on the wireless communication device, which comprises the steps of data transmission and data reception.
As shown in fig. 3, the processing method of the data transmission step includes:
a1: starting, the LoRa radio frequency chip management module initializes the MCU, external interrupt, SPI or USB bus related to the LoRa radio frequency chip, and GPIO (general purpose input/output) pin of the LoRa radio frequency chip;
a2: initializing all LoRa radio frequency chip related registers, configuring interruption, configuring a transceiving buffer and configuring fixed transceiving frequency by a channel management module;
a3: waiting for data to be sent;
a4: starting to send data, fragmenting the data according to the length of the data by a packet packaging module, and writing the data fragments into sending caches of different LoRa radio frequency chips respectively;
a5: configuring a LoRa radio frequency chip to send an interrupt, and after the data sheet is sent, the interrupt occurs;
a6: and D, judging whether data need to be sent at the time, if so, executing the step A4, and if not, executing the step A3.
As shown in fig. 4, in step a4, the packetization processing method of the packetization module includes:
and starting, judging whether the total length of the data is greater than n × M, wherein n is the number of LoRa radio frequency chips, M is the sending buffer size of the LoRa radio frequency chips, if yes, dividing the data according to the maximum length of each packet of data as M, if not, dividing the length of each packet of data according to the total length divided by n, and ending.
As shown in fig. 5, the processing method of the data receiving step includes:
b1: starting, the LoRa radio frequency chip management module initializes external interrupt, SPI or USB bus related to the MCU and the LoRa radio frequency chip, and GPIO pin of the LoRa radio frequency chip;
b2: initializing all LoRa radio frequency chip related registers, configuring interruption, configuring a transceiving buffer and configuring fixed transceiving frequency by a channel management module;
b3: waiting for a data reception interrupt;
b4: receiving interruption occurs to the LoRa radio frequency chip, and data reception is started;
b5: clearing the receiving interrupt;
b6: and the packet packaging module is used for packaging the received data slices according to a data protocol.
As shown in fig. 6, in step B6, the group packaging method of the group packaging module includes:
b61: reading the data received and cached by the LoRa radio frequency chip in sequence according to the interrupt sequence;
b62: analyzing data according to a data protocol, and arranging the data according to a packet sequence;
b63: all the data pieces are received, and the process is finished.
As shown in fig. 7 and 8, the data protocol format includes a total number of packets, a packet order, a data length, data, and a CRC (Cyclic Redundancy Check).
When two or more wireless communication devices communicate, the wireless communication devices only need to be configured with the same channel and frequency and placed in the transmission distance range of LoRa, and medium-rate communication can be achieved. In this example, each wireless communication device includes 6 LoRa rf chips sx127x, and the theoretical transmission rate can reach 225kbs by using 6 LoRa rf chips sx127x for concurrence. This rate can be extended far beyond the application scenario of the previous single slice sx127x, and of course, if more slices sx127x are used, the transmission rate will be faster.
The MCU of the wireless communication device for transmitting data divides the data into n data pieces, then the data pieces are respectively distributed to 6 sx127x, the 6 sx127x are transmitted simultaneously, the wireless communication device for receiving the data also comprises 6 sx127x, the data are received in one-to-one correspondence with the 6 sx127x for transmitting the data, and after the data are received, the data are sequenced according to a packet sequence and assembled into original data.
The above-described embodiments are intended to be illustrative, and not restrictive, of the invention, and all changes that come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein.