CC2530 RF part is used -realized point -to -point receivables

1 Introduction

This article will analyze a wireless serial port using the CC2530. The article will list some code and analyze the specific operations of the CC2530. The specific content of this article includes the following parts

  • CC2530 is a wireless transceiver chip that meets the standard 802.15.4 standard.But this article did not comply with the Rules of 802.15.4During the sending process, the network ID, source address, and target address were ignored, and frame filtration was prohibited during the receiving process. The use of the wireless part of the CC2530 wireless section through the process of sending and receiving processPossible and clear, explain the problem with the least code.
  • The debugging of wireless chips is difficult, and generally there are sending equipment and receiving equipment. In order to explain the use of wireless chips through the simplest code, only one device code is written in this article to achieve the sending and receiving function. The function of the device is also relatively simple. The CC2530 receives data from the serial port and sends the data through the RF part. At the same time, the CC2530 sends the data received from the RF part through the serial port to "non -destructive" to achieve wireless serial ports in this way.
  • The serial data is a "stream" packet, and the RF part is a "frame" packet. In the processing and analysis of serial port data, the data is generally used in specific string verbal and length, but this article uses a serial interval to receive data. This method is equivalent to the Modbus-RTU serial data processing method. This method of detecting byte data time interval allows the serial port of the CC2530Receive no special format requirementsData, truly realize wireless serial function.

[[[[[[Code warehouse】 The code warehouse is located in Bitbucket, please use HG cloned or download the ZIP package. Do not use any version of the IE browser, unless you know the impact of HTML4 and HTML5 on the browser, it is recommended to use Google or Firefox browser. Please switch to the speed mode.

[[[[[[Video link.


1.1 Experimental preparation

In order to achieve wireless serial function,Need to prepare two sets of CC2530 modules and a simulated deviceEssence If conditions permit can be added, the simulation device can be CC Debugger or SmartRF04EB. At the same time, you can also prepare a set of CC2531 usbdongle as a sniffer to grab the RF sending data for debugging and analysis.


1.2 Experimental results

This article mainly realizes the wireless serial function, and the serial port is used to debug the assistant to send byte data. For example, sending Hello CC2530 to Device A through serial port, device B can receive Hello CC2530, and print the string to the screen via serial debug assistant. Equipment B sends HELLO RF, and device A can also receive data and print to the screen.

 

Figure 1.2.1 (A-B) Equipment A and Equipment B serial debugging interface

PictureBracketThe number containsRSSI results, RSSI represents the receiving signal strength, such as -28 in the figure. The unit of the RSSI result is DBM, DBM is an absolute unit and the reference standard is 1MW.

2. Initialization

There are many registers in the RF part, and you need to read the data manual and related tools patiently to complete the settings. Although there are many registers in the RF part, they still use the helpSmartRF tool, data manual and example codeYou can still summarize the general method of using the CC2530 wireless part.

Initialization parts includeReceive data packet frame filtration control, transmit power control and channel selection; Use the SmartRF tool to generate several recommendation values; open the receiving terminal and enter the receiving state.

2.1 code

void rf_init ()
{{
 FRMFILT0 = 0x0C; // Static receiving filter, that is, receiving all data packets
 Txpower = 0xd5; // The transmitting power is 1DBM
 Freqctrl = 0x0b; // Select channel 11
 
 Ccactrl0 = 0xf8; // Recommended value SMARTRF software generation
 Fscal1 = 0x00;
 TxFILTCFG = 0x09;
 Agcctrl1 = 0x15;
Agcctrl2 = 0xfe;
 TxFILTCFG = 0x09;
 
 Rfirqm0 | = (1 << 6); // Make the RF packet receiving interruption
  IEN2 | = (1 << 0); // Enable RF to interrupt
 
  RFST = 0xed; // Clear the RF receiving buffer ISFLUSHRX
  RFST = 0xe3; // RF receiving enables to enable ISRXON
}

2.2 Analysis

The default value of FRMFILT0 is 0x0d, and the last one of the register isFrame_fliter_enThe specific meaning of this bit isEnable frame filtrationThe place plays an important role in the receiving process. The CC2530 is an RF chip that meets the 802.15.4 protocol. In the 802.15.4 protocol, the MAC layer has a fixed protocol format format and different types of commands. CC2530 can automatically filter the wireless data frame that does not need to be received,For example, the target address of the wireless data frame is not in line with the own address in the CC2530 register, then the CC2530 can ignore the wireless data frame without triggering the interruptEssence The specific filtering process can be viewed by the data manual, which is not explained in detail here. In order to achieve the simplest application, the CC2530 is prohibited from receiving any wireless data frame.

Regarding FRMCTRL0, the default value in this program is not reflected in the code. From the code searching online, the vast majority of code enables the auto_ack logo bit, which enables the CC2530 chip to automatically answer wireless data frames automatically. On the surface, the response mechanism of the CC2530 can ensure the reliability of wireless communication, but this response mechanism needs to follow the 802.15.4 standard.If you can answer automatically, the data packet sent by the CC2530 must also meet the 802.15.4 standard.In order to be as simple as possible,This program is prohibitedEssence

Regarding FRMCTRL0, AutoCRC defaults to enable state, CC2530 will automatically calculate and analyze the CRC verification.

SMARTRF can help to generate several relatively unpopular registersThese registers are related to the CC2530 wireless debugging and demodulation related parts, and in the process of actual use, the recommended value can be adopted.

At the end of the initialization, the RF receives terminal. Write through the RFST register to the empty receiving buffer and enter the receiving state command.

3. Sending process

3.1 code

void RF_SEND (Char*PBUF, Int len)
{{
  RFST = 0xe3; // RF receiving enables to enable ISRXON
  // Waiting for the state is not active and does not receive SFD
  While (fsmstat1 & ((1 << 1) | (1 << 5));
 
 Rfirqm0 & = ~ (1 << 6); // Forbidden to receive data packet interrupt
  IEN2 & = ~ (1 << 0); // Clear RF global interrupt
 
  Rfst = 0xee; // Clear the send buffer ISFLushtx
 Rfirqf1 = ~ (1 << 1); // Clear the sending of the sending complete
 
  // The filling process of filling needs to be added 2 bytes. The CRC check automatically fills
  Rfd = len+2;
  for (int i = 0; i <len; i ++)
  {{
    Rfd =*pbuf ++;
  }
 
  Rfst = 0xe9; // Send the data packet iStxon
  While (! (RFIRQF1 & (1 << 1)); // Wait for the sending to complete
 Rfirqf1 = ~ (1 << 1); // Clear the sending of the sending complete
 
 Rfirqm0 | = (1 << 6); // RX receiving interrupt
  IEN2 | = (1 << 0);
}

3.2 Analysis

The sending process itself is not difficult, it can be roughly divided intoListen to the SFD clearing channel, close the receiving interrupt, fill the buffer, start and send and wait for the sending, and finally resume the receiving interruptEssence The only thing that needs to be explained in these processes is to fill the buffer process. During the initialization process, the FRMCTRL0 register is mentioned. Part of the first byte is the length domain,You need to fill in the length domain before filling in the actual load,The physical layer load is increased by 2 on the basis of the original length. The reason why the length domain value increases 2 is due to the existence of automatic CRCThe CRC part accounted for two bytes of CC2530 to fill these two bytes to send buffer.

4. Receive process

Slightly different from the sending part, the receiving part can be divided intoReceive interrupt parts and receive data frame processing partsEssence

4.1 code

#Pragma vector = rf_vector
__interrupt void RF_ISR (VOID)
{{
  EA = 0;
 
  // Receive a complete data packet
  if (RFIRQF0 & (1 << 6))
  {{
   rf_receive_isr (); // Call the receiving interrupt processing function
   S1con = 0; // Clear the RF interrupt logo
Rfirqf0 & = ~ (1 << 6); // Clear RF receiving complete data packet interrupt
  }
  Ea = 1;
}
void rf_receive_isr ()
{{
  int rf_rx_len = 0;
  int RSSI = 0;
  CHAR CRC_OK = 0;
 
 RF_RX_LEN = RFD-2; // Remove two-byte additional results in length
 rf_rx_len & = 0x7f;
  for (int i = 0; I <rf_rx_len; i ++)
  {{
   RF_RX_BUF [i] = rfd; // Read the content of receiving buffer in a row
  }
 
  RSSI = RFD-73; // Read RSSI results
 CRC_OK = RFD; // Read the CRC verification results bit7
 
  Rfst = 0xed; // Clear the receiving buffer
  if (CRC_OK & 0x80)
  {{
   uart0_sendbuf (rf_rx_buf, rf_rx_len); // serial port sending
   Printf ("[%d]", rssi);
  }
  else
  {{
   Printf ("\ r \ nCRC error \ r \ n");
  }
}

4.2 Analysis

The wireless receiving part can be divided into two contents,One is a wireless receiving interrupt processing, and the other is wireless data frame processingEssence In the former, you only need to query the logo bit. The sixth bit of RFIRQF0 is the complete data packet receiving interrupt logo. If the CC2530 receives a complete wireless packet, the flag position will be placed. Since the CC2530 has a variety of RF interrupt types, such as receiving a complete frame, the frame through filtering, etc., after entering the interrupt service function, you can enter the corresponding processing task by querying the logo. Method.

After entering the data package processing function, first read the first byte of the receiving buffer,The first word is the data packet length, You need to subtract 2 here. The principle of the length of the length is similar to the sending process. The last two bytes were originally CRC verification, but it was filled with more useful information during the CC2530 processing process.For example, RSSI results, while the CRC verification only returns the result without returning the value. The result of the CRC verification only occupies oneEssence

If the CRC verification is successful, then read the receiving buffer byte data in turn, send these byte data through the serial port, and add a RSSI result and RSSI are surrounded by brackets. If the CRC verification fails, the CRCERROR is printed through the serial port.In the process of debugging the program, the result of the CRC check was a "flower frame", but in fact, it was found that when the CC2530 was in a receiving state, the data would be received from time to time.These data are chaotic, and the only feature is that the CRC verification results are wrong. Through the CRC verification results, data can be effectively eliminated to ensure the reliability of the system. For example, the program provided hereThen CRC Error appears every half an hour.


Figure 4.2.1 CRC error phenomenon

5. serial portal

The content of the serial port has nothing to do with the RF part, but in order to facilitate debugging, the code is listed. The code of the serial port includes two parts: timer T1 and UART. During the UART interrupt, fill in the data and restart the timer. In the timer interrupt, the serial port data is accepted to change a software flag bit is_serial_Receive.

5.1 code

void uart0_init ()
{{
 PERCFG = 0x00; // UART0 Select position 0 tx@p0.3 rx@p0.2
  P0sel | = 0x0c; // p0.3 P0.2 Select peripheral function
  U0CSR | = 0xc0; // UART mode receiver enable
  U0gCr | = 11; // Check the table to get U0GCR and U0baud
 U0baud = 216; // 115200
 UTX0IF = 1;
 
 URX0IE = 1; // to allow the receiving interruption IEN0@bit2
}
void timer1_init ()
{{
  T1CTL = 0x0C; @DIV frequency division coefficient 128 @mode pause operation
 T1CCTL0 = 0x44; @im channel 0 interruption to enable @mode comparative matching mode
 T1Stat = 0x00; // Clear all interrupt signs
 
  T1Ie = 1; // IEN1@Bit1 to enable timer 1 to interrupt
 
 T1CC0L = 250; // The overflow cycle is 2ms
 T1CC0H = 0;
}
 
void timer1_disbale ()
{{
  T1CTL & = ~ (1 << 1); // Restore to stop mode
}
 
void timer1_enable ()
{{
  T1CTL | = (1 << 1); // The change mode is the matching mode mode = 0x10;
 T1Stat = 0x00; // Clear the interrupt logo position
 T1cNTH = 0; // Start count again
 T1CNTL = 0;
}
 
#Pragma vector = urx0_vector
__InterRupt void uart0_ISR (VOID)
{{
 Urx0if = 0; // Clear the receiving interrupt logo
 Serial_rxbuf [Serial_rxpos] = U0DBUF; // Fill buffer
 serial_rxpos ++;
 Serial_rxlen ++;
 
timer1_enable (); // The timer starts to count
}
 
#Pragma vector = t1_vector
__interrupt void timer1_ISR (VOID)
{{
 T1Stat & = ~ (1 << 0); // Clear the timer T1 channel 0 interrupt logo
 
 is_serial_Receive = 1; // serial port data arrives
 Timer1_disbale ();
}

6. Summary

Most RF chips can be divided into initialization, receiving and sending these three processes. The initialization process can include set channels, power, frame filtration and other parameters. Because RF chip registers are more, the recommendation value can be generated through the official software. The sending process can be used to wait, and the receiving process is often used.



  • 36
    like
  • Step on
  • 35
    collect
  • Reward
    Reward
  • 64
    Comment

"Related recommendation" is helpful to you?

  • Very unreasonable
  • Not help
  • generally
  • helpful
  • Very helpful
submit
C ️2022 CSDN Skin theme: Technical Factory Designer: CSDN official blog Return homepage
Comment 64

Reward author

xukai871105

Your encouragement will be the biggest motivation for my creation

Mortar ¥ 4 6th ¥ ¥ ¥ ¥ ¥ Mortar 20
Enter 1-500 integer
Balance payment (Balance:-)
Coding payment
Code payment:Mortar
Obtain
Coding payment

If your balance is insufficient, please replace the code scan payment orRecharge

Reward author

Actually paidYuan
Use balance payment
Click to get it again
Coding payment
Wallet balance 0

Deducting instructions:

1. The balance is a virtual currency for the recharge of wallets. The payment amount is deducted at a ratio of 1: 1.
2. The balance cannot be purchased and downloaded directly. You can buy VIP, C coin sets, paid columns and courses.

Balance recharge