Design of wireless data transmission system based on nRF24L01 and PIC16F877

Publisher:tau29Latest update time:2011-08-26 Source: EEWORLD Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

In industrial control sites, it is often necessary to collect a large amount of field data, such as temperature, humidity, air pressure, etc., and transmit these data to the host for processing. The host transmits the control signal to the field execution module for various operations based on the processing results. It can be seen that the data from the acquisition device to the processing terminal, and the monitoring control instructions from the processing terminal to the acquisition device, all need to go through the important link of the transmission process. When the data acquisition point is in motion, or the environment does not allow the laying of cables, the acquisition device must be separated from the terminal device, and data can only be transmitted wirelessly. Based on this, this paper designs a wireless data transmission system, which uses Microchip's PIC16F877 microcontroller to control Nordic's wireless digital transmission chip nRF24L01, and transmits data bidirectionally through wireless. Experimental results show that the system is flexible to use, low cost, and can be easily embedded in the wireless monitoring system.

1. System overall structure design

Figure 1 is the overall block diagram of the system design. The main control chip of this wireless data transmission system uses Microchip's PIC16F877 microprocessor, which is responsible for controlling the wireless chip L01 to achieve wireless data transmission. In order to collect multi-channel data, 10 A/D chips are used for time-sharing sampling, and their working sequence is controlled by CPLD. The data collected from each channel is processed by the microcontroller and then transmitted wirelessly. As for when to sample, it is determined by the Trigger signal sent by the microcontroller. In terms of communication with the computer, the system uses a USB chip to send the wireless received data to the computer through the USB port and store it in a binary file. When the transmission is completed, the VB reading software is run to read the collected signal for analysis.

2. System hardware design

2.1 Data Collection

The data acquisition part is mainly composed of sensors, low-pass filter amplifiers, A/D and CPLD. The power management mainly provides suitable working voltage for each chip and provides 1MHZ master clock input for CPLD. This system uses 10 AD7492 chips, which can sample 10 analog signals. CPLD mainly controls the sampling and reading timing of 10 A/D chips. The sampling rate is determined by the frequency divider inside CPLD and the size of wireless transmission rate. In order to cooperate with the work of wireless transmission module, trigger sampling is adopted here. That is, a D flip-flop is designed inside CPLD, and VCC is connected to the D input terminal, and the Trigger signal is used as the clock input, as shown in Figure 2. After the system is powered on, CPLD detects its pin Trigger terminal. When a rising edge appears, the D flip-flop outputs a high level, opens the NAND gate, and Convast outputs a 1KHz signal, and A/D sampling begins.

2.2 Wireless transmission part

Data transmission is mainly achieved by controlling the wireless RF chip L01 using the PIC16F877 microcontroller. nRF24L01 is a single-chip RF transceiver chip that operates in the 2.4-2.5GHz ISM band, with an operating voltage of 1.9V-3.6V and an operating temperature of -40℃-+85℃. It has up to 125 channels to choose from, a maximum communication rate of 2Mbit/s, and has automatic response and retransmission functions. Its operating parameters are all configured through the chip status word, and these configuration words are accessed by the PIC16F877 through SPI[1]. The main technologies of L01 are:

Working mode: CE, CSN, SCK, MOSI, MISO, IRQ are the control pins of the chip. The microprocessor can determine the working mode of the chip by controlling these 6 pins. When PWR_UP, PRIM_RX and CE are "111", L01 is in receiving mode; when it is "101", it is in transmitting mode; when it is "1X0", it is in idle mode 1; when it is "0XX", it is in power-down mode.

Enhanced ShockBurst technology: L01 incorporates enhanced ShockBurst technology, which makes the two-way communication protocol simple. In a typical two-way communication, when the receiver receives the data from the transmitter, it will send a response signal back to the transmitter. If the receiver does not receive the data, the transmitter will automatically resend the data packet after a certain delay time (when the automatic resend function is turned on), and this does not require the participation of the CPU.

Data channel: When L01 is in receiving state, it can receive data from 6 different channels. Each channel has its own channel address, but shares the same channel. In other words, an L01 configured in receiving mode can communicate with 6 L01s configured in transmitting mode, and the receiver can distinguish them according to their channel addresses. Channel 0 has a 40-bit address, and channels 1-5 share the upper 32-bit address, but the lower 8 bits are different. Each channel can turn on the automatic retransmission and automatic response functions. When L01 in receiving state returns the response signal, it will use the address of the receiving channel as the transmitting address of the transmitting response signal. In the transmitting device, channel 0 is often used to receive the response signal. The address of the transmitted data must be consistent with the address of the receiving channel 0, so that the response signal can be effectively received.

Data packet description: "1-byte header + 3-5-byte address + 9-bit flag + 1-2-byte CRC". When L01 wants to send data, the microcontroller must first write the address and valid data into the L01 buffer, and then L01 automatically generates the header and CRC check code before sending it out.

2.3 USB interface design

The system uses the USB chip FT245, and the read and write operations are controlled by the microcontroller. FT245 provides some status flags (RXF, TXE) for the microcontroller to query, so that the microcontroller can send read and write pulses to perform read and write operations. The control is very simple.

3. Software Design

To design the system software well, its working principle must be clear: first, power on the transmitter, configure its L01 as PRX, and put it into receiving mode to wait for the handshake instruction from the host. At this time, the acquisition device does not start working. Then connect the receiver to the computer through the USB interface, run the VB program, click the start test button, and the handshake instruction (H'33') will be transmitted through the receiver's L01 (power-on configured as PTX). After receiving the handshake instruction, the transmitter must make a judgment. If it is not H'33', it will continue to wait for the handshake instruction; if it is, it means that the two parties have established a successful connection. At this time, the transmitter's L01 is configured as PTX, and the single-chip microcomputer sends a high-level pulse with a pulse width of 3.6us to the acquisition device to activate the A/D and start sampling. The sampling rate is 1KHz. Since each sensor signal must be sampled by the A/D and converted into a 12-bit digital quantity (considered to be 2 Byte), then 10 channels are 20 Byte, which are sent to L01 for packaging and transmission after being processed by the single-chip microcomputer. After 350us, the receiver receives the data and writes it into the computer buffer in real time through the microcontroller and USB chip. In this way, the two sides transmit data 10,000 times, 20 bytes each time. After the transmission is completed, the data curve will be displayed in real time on the VB interface.

Based on the above analysis, the system software is divided into two parts: the single-chip microcomputer control program and the computer interface program. The former mainly completes the acquisition and wireless transmission of multi-channel signals with nRF24L01 as the core, while the latter completes the display of signals for researchers to analyze. This article only introduces the control program, which adopts a modular programming method and is divided into two parts: the transmitter program and the receiver program. Its flow chart is shown in Figure 3.

Since the acquisition system samples at 1KHz, that is, 20Byte of data is sent every 1ms, the wireless part needs 1ms for one transmission. If the receiver executes the receiving subroutine for less than 1ms, it must be delayed to make up for it in order to synchronize with the transmission. In addition, an 800us timer interrupt is specially set in the receiver program to prevent the receiver from waiting for a long time due to failure to receive data, which affects the data transmission efficiency.

4. Problem Analysis

There are some problems in the operation of this system, which make it unable to work normally. The following are the explanations:

① L01 has problems in the sending and receiving conversion;

Cause: The configuration word is not written into L01.

② When transmitting data, it is found that the lower eight bits are zero, but the upper four bits are numbers;

Reason: The PSP function of the microcontroller was turned on, causing the D port to be unusable.

③ The data transmission waveform is seriously distorted;

Cause: There is a problem with the wireless module's synchronization of sending and receiving, and there is no one-to-one correspondence between data packets.

5. Experimental results

This system needs to perform 10,000 data transmissions, with 20 bytes transmitted each time. When transmitting data, the synchronization of the transmitter and the receiver must be ensured, otherwise there will be misalignment between the data packets, and the obtained data curve will be seriously distorted, affecting the analysis, so the synchronization problem occupies an important position in the wireless data transmission system. Attached is the wireless data transmission waveform of this system under good synchronization, see Figure 4. The 10 curves in the figure are the sensor signals sampled by 10 A/Ds and transmitted wirelessly to the computer and displayed through the VB interface. The curves with higher amplitudes in the middle are two sine waves, and the rest are baselines.

6. Conclusion

The system is easy to control, stable in operation, and can achieve reliable wireless data transmission. A large number of experimental measurements show that the average transmission rate of the system can reach 256Kbps, and the average bit error rate is only 0.2%, which can meet the needs of most wireless data transmission.

Reference address:Design of wireless data transmission system based on nRF24L01 and PIC16F877

Previous article:Design and implementation of a hydrological cableway testing system
Next article:Pico-projector solution based on Microchip MCU

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号