当前位置:网站首页>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
边栏推荐
- Significance and requirements of semiconductor particle control
- IEEE access personal contribution experience record
- Scm-05 basis of independent keyboard
- Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
- C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
- Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
- Detailed explanation of pragma usage
- 研究發現,跨境電商客服系統都有這五點功能!
- Summary -st2.0 Hall angle estimation
- Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
猜你喜欢
Consul安装
UEFI development learning 2 - running ovmf in QEMU
找不到实时聊天软件?给你推荐电商企业都在用的!
The research found that the cross-border e-commerce customer service system has these five functions!
如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
C language uses arrays to realize the intersection, union, difference and complement of sets
Hardware 1 -- relationship between gain and magnification
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
Altium designer 19.1.18 - change the transparency of copper laying
A simple method to prove 1/t Fourier transform
随机推荐
UEFI development learning 2 - running ovmf in QEMU
Halcon's practice based on shape template matching [1]
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
Programming knowledge -- assembly knowledge
Gradle composite construction
Summary -st2.0 Hall angle estimation
Global and Chinese market of resistivity meter 2022-2028: Research Report on technology, participants, trends, market size and share
软件设计师:03-数据库系统
IEEE access personal contribution experience record
Detailed explanation of pragma usage
万字详解八大排序 必读(代码+动图演示)
Altium designer 19.1.18 - hide the fly line of a network
Global and Chinese markets for medical oxygen machines 2022-2028: Research Report on technology, participants, trends, market size and share
Network port usage
Scm-05 basis of independent keyboard
The research found that the cross-border e-commerce customer service system has these five functions!
研究發現,跨境電商客服系統都有這五點功能!
Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
Connection mode - bridge and net
Define in and define out