当前位置:网站首页>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
边栏推荐
- UEFI development learning 3 - create UEFI program
- Global and Chinese markets of large aperture scintillators 2022-2028: Research Report on technology, participants, trends, market size and share
- How to migrate the device data accessed by the RTSP of the easycvr platform to easynvr?
- Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
- Global and Chinese market of core pallets 2022-2028: Research Report on technology, participants, trends, market size and share
- Record the visual shock of the Winter Olympics and the introduction of the screen 2
- 导电滑环磨损快的原因
- Reasons for rapid wear of conductive slip rings
- Process communication mode between different hosts -- socket
- Global and Chinese markets for medical oxygen machines 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Makefile application

Application of ultra pure water particle counter in electronic semiconductors
![C WinForm [help interface - send email] - practice five](/img/2a/c4e7abe054e6fdd45acc7d297a033d.jpg)
C WinForm [help interface - send email] - practice five

万字详解八大排序 必读(代码+动图演示)

MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一

Altium Designer 19.1.18 - 更改铺铜的透明度

Train your dataset with yolov4
![C WinForm [display real-time time in the status bar] - practical exercise 1](/img/9f/d193cbb488542cc4c439efd79c4963.jpg)
C WinForm [display real-time time in the status bar] - practical exercise 1

Network port usage

Network communication model -- Network OSI tcp/ip layering
随机推荐
Cadence simulation encountered "input.scs": can not open input file change path problem
C language enhancement -- pointer
Detailed explanation of C language pointer
1-stm32 operation environment construction
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
Scm-05 basis of independent keyboard
The research found that the cross-border e-commerce customer service system has these five functions!
The global and Chinese market of lithographic labels 2022-2028: Research Report on technology, participants, trends, market size and share
Software designer: 03 database system
String judgment
STM32 learning method
C WinForm [realize the previous and next selection pictures] - practice 7
. Net service governance flow limiting middleware -fireflysoft RateLimit
Global and Chinese market of urban rail connectors 2022-2028: Research Report on technology, participants, trends, market size and share
Makefile application
Global and Chinese markets for flexible endoscopic lithotripsy devices 2022-2028: Research Report on technology, participants, trends, market size and share
Improve lighting C program
How to define guid in AMI code
Altium designer 19.1.18 - clear information generated by measuring distance
Some tips for using source insight (solve the problem of selecting all)