当前位置:网站首页>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
边栏推荐
- Good websites need to be read carefully
- ·Practical website·
- The research found that the cross-border e-commerce customer service system has these five functions!
- Detailed explanation of pragma usage
- IEEE access personal contribution experience record
- C WinForm [display real-time time in the status bar] - practical exercise 1
- Global and Chinese market of resistivity meter 2022-2028: Research Report on technology, participants, trends, market size and share
- A simple method to prove 1/t Fourier transform
- Programming knowledge -- assembly knowledge
- Record the opening ceremony of Beijing Winter Olympics with display equipment
猜你喜欢

Altium Designer 19.1.18 - 清除测量距离产生的信息

Improve lighting C program
![Halcon's practice based on shape template matching [1]](/img/68/206eed7502fbf108a929aa9365b1ae.jpg)
Halcon's practice based on shape template matching [1]

Ads learning record (lna_atf54143)
![Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine](/img/13/22a1915329f58acd54c40176f6f301.jpg)
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine

Network communication model -- Network OSI tcp/ip layering
![Halcon's practice based on shape template matching [2]](/img/70/3e905661785e570fb406b8e97d41e6.jpg)
Halcon's practice based on shape template matching [2]

Hardware 3 -- function of voltage follower

C language # and #

Altium designer 19.1.18 - Import frame
随机推荐
Network communication model -- Network OSI tcp/ip layering
Bootloader implementation of PIC MCU
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
Hardware 3 -- function of voltage follower
[popular science] some interesting things that I don't know whether they are useful or not
1089 Insert or Merge 含测试点5
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
How to excavate and research ideas from the paper
Global and Chinese markets for flexible endoscopic lithotripsy devices 2022-2028: Research Report on technology, participants, trends, market size and share
Altium designer 19.1.18 - Import frame
Hardware 1 -- relationship between gain and magnification
Shell脚本基本语法
Summary -st2.0 Hall angle estimation
Altium Designer 19.1.18 - 导入板框
Global and Chinese markets for recycled boilers 2022-2028: Research Report on technology, participants, trends, market size and share
IC software learning
.NET服务治理之限流中间件-FireflySoft.RateLimit
Altium designer 19.1.18 - clear information generated by measuring distance
Cadence simulation encountered "input.scs": can not open input file change path problem