极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17446|回复: 5

关于enc28j60 和 nrf24l01 同时使用的问题

[复制链接]
发表于 2013-4-13 14:51:47 | 显示全部楼层 |阅读模式
参考了前辈们的文章:
http://www.geek-workshop.com/for ... thread&tid=2520
http://www.geek-workshop.com/for ... thread&tid=1228
想做个室外温度采集,采集端用的是一块arduino mini,温度感应模块采集温度数据然后用nrf24l01传送给接收端,接收端是arduino uno,nrf24l01接到数据后由enc28j60网络模块上传到yeelink,自己试着整合了一下代码,但是通不过编译,跪求大神指点啊!!! (编译环境1.01)

#include "SPI.h"
#include "Mirf.h"
#include "nRF24L01.h"
#include "MirfHardwareSpiDriver.h"
#include <EtherCard.h>
#define OUT
#define REQUEST_RATE 10000 // milliseconds
#define SENSOR1 4
#define SENSOR2 5
#define SENSOR3 6
#define LANcsPin 8
#define RFcsPin 10
int data;
int aaa;
int aaaa;
// ethernet interface mac address
static byte mymac[] = {
  0x74,0x69,0x69,0x2D,0x30,0x31 };

// remote website name
char website[] PROGMEM = "api.yeelink.net";
char urlBuf[] PROGMEM = "/v1.0/device/2464/sensor/3315/datapoints";
char apiKey[] PROGMEM = "U-ApiKey: -------------------------------------------";

byte Ethernet::buffer[700];
static long timer;

// called when the client request is complete
static void my_result_cb (byte status, word off, word len) {
  Serial.print("<<< reply ");
  Serial.print(millis() - timer);
  Serial.println(" ms");
  Serial.println((const char*) Ethernet::buffer+off);
}

void setup () {
  SPI.begin();
  pinMode(LANcsPin,OUTPUT);
  pinMode(RFcsPin,OUTPUT);
  Serial.begin(9600);
  Serial.println("[getDHCPandDNS]");
  digitalWrite(RFcsPin,HIGH);
  digitalWrite(LANcsPin,LOW);
  randomSeed(analogRead(0));
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");

  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("My IP: ", ether.myip);
  // ether.printIp("Netmask: ", ether.mymask);
  ether.printIp("GW IP: ", ether.gwip);
  ether.printIp("DNS IP: ", ether.dnsip);

  if (!ether.dnsLookup(website))
    Serial.println("DNS failed");
  ether.printIp("Server: ", ether.hisip);

  timer = - REQUEST_RATE; // start timing out right away
  digitalWrite(LANcsPin,HIGH);
  digitalWrite(RFcsPin,LOW);
  Mirf.spi = &MirfHardwareSpi;   //加载24L01  SPI
  Mirf.init();
  Mirf.setRADDR((byte *)"serv1");//接收到"接收地址"
  Mirf.payload = sizeof(int);   //接收类型(整数)
  Mirf.config();
}
void loop () {
  if(Mirf.dataReady()){
     Mirf.getData((byte *)&data); //接收数据
     aaa = data;
     Mirf.rxFifoEmpty();
  }
  delay(10);
  digitalWrite(RFcsPin,HIGH);
  digitalWrite(LANcsPin,LOW);
   ether.packetLoop(ether.packetReceive());
  if ((millis() > timer + REQUEST_RATE) && !aaa == aaaa) {
    aaaa = aaa;
    timer = millis();
    Serial.println(">>> REQ");
    static char buf[20];
    get_send_string(buf);
    if (!ether.dnsLookup(website))
      Serial.println("DNS failed");
    ether.printIp("Server: ", ether.hisip);
    ether.httpPost (urlBuf, website, apiKey, buf, my_result_cb);
  }
}
void get_send_string(OUT char *p){
  if (!aaaa == 1111){
  uint16_t whole = 50;
  sprintf(p,"{\"value\":%d}",whole);}
else{
   uint16_t whole = 0;
  sprintf(p,"{\"value\":%d}",whole);}
   
}
回复

使用道具 举报

发表于 2013-4-13 18:01:12 | 显示全部楼层
本帖最后由 zcbzjx 于 2013-4-13 18:03 编辑

参看我这个就行了http://microduino.blog.163.com/b ... 920121111102524322/

nrf24库的默认发送数量是1Mbps,如果距离比较远,建议用250kbps,咋个改,请查看下库文件。我的模块用250kbps基本上能穿2堵非承重墙。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-4-14 00:02:33 | 显示全部楼层
本帖最后由 葱头同学 于 2013-4-14 00:11 编辑
zcbzjx 发表于 2013-4-13 18:01
参看我这个就行了http://microduino.blog.163.com/blog/static/21327824920121111102524322/

nrf24库的默 ...


张老师,参考你文章的程序已经成功了一半,uno接收端enc28j60模块正常初始化,正确返回My IP、GW IP、DNS IP、Server信息,不知道nrf24模块是否正常初始化,因为mini发射端好像不能发送数据,打开串口监视也只是跳了一个欢迎信息就停止了,既没有“Sending...."、也没有"ok","failed"。

接线是按照文中给出的表接的,检查过接线并没有接错。文中使用的库是从google搜索的,不知是否还需要更改库文件?

RF24库:https://github.com/maniacbug/RF24
RF24Network库:https://github.com/maniacbug/RF24Network/tree/gh-pages

ENC28J60: INT --> D3 ;  CS --> D8 ; MOSI --> D11 ; MISO --> D12 ; SCK --> D13

NRF24L01:+: IRQ --> D2 ;  CSN --> D9 ; CE --> D10 ; MOSI --> D11 ; MISO --> D12 ; SCK --> D13
回复 支持 反对

使用道具 举报

发表于 2013-4-14 00:43:04 | 显示全部楼层
接线int 和irq arduino的库都是不用的,当然接了也不会错。 别的接线应该都对。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-4-21 22:17:17 | 显示全部楼层
本帖最后由 葱头同学 于 2013-4-21 23:21 编辑
zcbzjx 发表于 2013-4-14 00:43
接线int 和irq arduino的库都是不用的,当然接了也不会错。 别的接线应该都对。


nrf24L01模块已经能初始化,但是接收又出了问题 发送提示sending..ok 接收端没反应,慢慢调试吧...
回复 支持 反对

使用道具 举报

发表于 2013-12-17 22:26:37 | 显示全部楼层
ENC28J60,NRF24L01 都是SPI口,一个板子能同时接D10-D13?
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-10 11:13 , Processed in 0.040541 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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