当前位置:网站首页>Arduino uses nrf24l01+ communication
Arduino uses nrf24l01+ communication
2022-07-05 08:01:00 【Drink more hot water-】
Arduino Originally meant as open source to open up , There are a lot of Libraries , But uneven , This 24L01+ Many libraries have been changed all nm no way , It's speechless , I found a program on the Internet Changed , Finally, we can communicate simply
Record :
CE: Module control line ,CSN For the low ,CE synergy CONFIG Registers jointly decide NRF24L01 state
CSN: SPI Film selection line
SCK: SPI Clock line
MOSI:SPI cable ( Host output slave input )
MISO:SPI cable ( Host input and slave output )
IRQ: Break the signal line . Becomes low when interrupted , It becomes lower in the following three cases :Tx FIFO Send and receive ACK( Can make ACK Under the circumstances )、Rx FIFO Receive the data 、 Maximum number of retransmissions reached
There is no need to interrupt here ,Arduino UNO Just let it go 2 Middle fracture , This kind of amateur MCU Inquiry does not delay things
This kind of wireless communication module is usually bound to address , Fixed channel , FM or something , Fixed routine , Here is a simulation SPI The driver , After simple verification, it can send and receive
Attach code :
Here we receive data from the serial port , use NRF Send out , On the other end 2.4g After receiving, the serial port will print , All raw data , No agreement
TX
#include "NRF24L01.h"
String comdata = "";// String function
#define TX_NAME "32899"
/* Statement nRF24L01 */
nRF24L01 nrf24;
/* Create send data cache , Initialize to 0 */
char buf[12] = {
0};
void setup() {
Serial.begin(9600);
/* initialization nrf24 */
nrf24.init();
/* Configure data width */
nrf24.payload = 10;
/* Configure address */
nrf24.setTADDR(TX_NAME);
/* Write configuration */
nrf24.config();
}
void loop() {
recv_uart_cmd();
if (comdata.length() > 0)// If comdata There's data
{
//Serial.println(comdata);// Print comdata data
strcpy(buf, comdata.c_str());
Serial.println(buf);// Print comdata data
comdata = "";
nrf24.send(buf);
}
}
void recv_uart_cmd(void)
{
if (Serial.available() > 0)// Read whether the serial port has data
{
comdata = "";// Cache reset
while (Serial.available() > 0)// Whether the circular serial port has data
{
comdata += char(Serial.read());// Stack data to comdata
delay(2);// Delay waiting for response
}
//if (comdata.length() > 0)// If comdata There's data
//{
// Serial.println(comdata);// Print comdata data
//}
}
}
RX :
#include "NRF24L01.h"
#define RX_NAME "32899"
/* Statement nRF24L01 */
nRF24L01 nrf24;
/* Establish receive data cache , Initialize to 0 */
char buf[15];
int recv_cmd = 0;
void setup() {
Serial.begin(9600);
nrf24.init();
nrf24.payload = 10;
nrf24.setRADDR(RX_NAME);
nrf24.config();
/* Set interrupt */
//attachInterrupt(0, readData, LOW) ;
}
void loop() {
readData ();
}
void readData (void)
{
if (nrf24.dataReady())
{
//Serial.println("Receiving the data!");
nrf24.getData(buf);
Serial.print("Data -> ");
//Serial.print(buf);
recv_cmd = atoi(buf);
Serial.print(recv_cmd);
Serial.println(" ");
}
}
Finally, the most important thing is to have Driven library support
This folder is in Arduino Under the installation folder , The definition of pins is in
NRF24L01. in
/* Interrupt state */
#define RX_IRQ 11
#define TX_IRQ 22
#define MAX_RT_IRQ 33
/* Default port number */
#define CE 8 // CE_BIT: Digital Input Chip Enable Activates RX or TX mode
#define CSN 10 // CSN BIT: Digital Input SPI Chip Select
#define SCK 13 // SCK BIT: Digital Input SPI Clock
#define MOSI 11 // MOSI BIT: Digital Input SPI Slave Data Input
#define MISO 12 // MISO BIT: Digital Output SPI Slave Data Output, with tri-state option
Examples It's inside TX RX Of Arduino Program , You can use it directly
Finally, the download link of the library is attached :
https://download.csdn.net/download/weixin_39369053/19619997
click here
over
边栏推荐
- Introduction of air gap, etc
- Factors affecting the quality of slip rings in production
- Altium Designer 19.1.18 - 清除测量距离产生的信息
- Volatile of C language
- Extern keyword function
- C language enhancement -- pointer
- Hardware 1 -- relationship between gain and magnification
- Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
- Detailed explanation of pragma usage
- 通过sql语句统计特定字段出现次数并排序
猜你喜欢
PMSM dead time compensation
Carrier period, electrical speed, carrier period variation
Step motor generates S-curve upper computer
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
High end electronic chips help upgrade traditional oil particle monitoring
Consul安装
A simple method to prove 1/t Fourier transform
Halcon's practice based on shape template matching [2]
Network port usage
UEFI development learning 5 - simple use of protocol
随机推荐
Altium Designer 19.1.18 - 导入板框
[untitled] record the visual shock of the Winter Olympics and the introduction of the display screen
Fundamentals of C language
STM32 learning method
Altium Designer 19.1.18 - 清除测量距离产生的信息
Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
Altium designer 19.1.18 - hide the fly line of a network
Consul installation
Significance and requirements of semiconductor particle control
Relationship between line voltage and phase voltage, line current and phase current
About yolov3, conduct map test directly
研究发现,跨境电商客服系统都有这五点功能!
找不到实时聊天软件?给你推荐电商企业都在用的!
Shell脚本基本语法
Beijing Winter Olympics opening ceremony display equipment record 3
Random function usage notes
Screen record of the opening ceremony of the Beijing winter olympics 2
Global and Chinese markets for flexible endoscopic lithotripsy devices 2022-2028: Research Report on technology, participants, trends, market size and share
·Practical website·
[professional literacy] specific direction of analog integrated circuits