极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10960|回复: 0

nRF24L01模块不能完成收发

[复制链接]
发表于 2014-7-23 11:01:12 | 显示全部楼层 |阅读模式
最近在准备做一套远程采集的东西,使用了nRF24L01模块,在测试的时候,使用了RF24Network类库的例子,helloworld_rx和,接线按照SPI接口(D11,D12,D13),CE为D9,片选CSN为D10。 发送端始终发送失败 显示 Sending...failed,接受端无反应。请问大家知道问题在哪里吗。还有个问题,如果只启动发送端,不启动接受端,发送正常的话会显示 Sending...ok吗

[pre lang="arduino" line="1" file="helloworld_tx"]
/*
Copyright (C) 2012 James Coliz, Jr. <[email protected]>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

/**
* Simplest possible example of using RF24Network
*
* TRANSMITTER NODE
* Every 2 seconds, send a payload to the receiver node.
*/

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 1;

// Address of the other node
const uint16_t other_node = 0;

// How often to send 'hello world to the other unit
const unsigned long interval = 2000; //ms

// When did we last send?
unsigned long last_sent;

// How many have we sent already
unsigned long packets_sent;

// Structure of our payload
struct payload_t
{
  unsigned long ms;
  unsigned long counter;
};

void setup(void)
{
  Serial.begin(57600);
  Serial.println("RF24Network/examples/helloworld_tx/");

  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
}

void loop(void)
{
  // Pump the network regularly
  network.update();

  // If it's time to send a message, send it!
  unsigned long now = millis();
  if ( now - last_sent >= interval  )
  {
    last_sent = now;

    Serial.print("Sending...");
    payload_t payload = { millis(), packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header,&payload,sizeof(payload));
    if (ok)
      Serial.println("ok.");
    else
      Serial.println("failed.");
  }
}
// vim:ai:cin:sts=2 sw=2 ft=cpp[/code]

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-7 06:44 , Processed in 0.076085 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表