关于enc28j60 和 nrf24l01 同时使用的问题
参考了前辈们的文章:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=2520
http://www.geek-workshop.com/forum.php?mod=viewthread&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;
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("");
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; //加载24L01SPI
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;
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);}
} 本帖最后由 zcbzjx 于 2013-4-13 18:03 编辑
参看我这个就行了http://microduino.blog.163.com/blog/static/21327824920121111102524322/
nrf24库的默认发送数量是1Mbps,如果距离比较远,建议用250kbps,咋个改,请查看下库文件。我的模块用250kbps基本上能穿2堵非承重墙。 本帖最后由 葱头同学 于 2013-4-14 00:11 编辑
zcbzjx 发表于 2013-4-13 18:01 static/image/common/back.gif
参看我这个就行了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 接线int 和irq arduino的库都是不用的,当然接了也不会错。 别的接线应该都对。 本帖最后由 葱头同学 于 2013-4-21 23:21 编辑
zcbzjx 发表于 2013-4-14 00:43 static/image/common/back.gif
接线int 和irq arduino的库都是不用的,当然接了也不会错。 别的接线应该都对。
nrf24L01模块已经能初始化,但是接收又出了问题 发送提示sending..ok 接收端没反应,慢慢调试吧... ENC28J60,NRF24L01 都是SPI口,一个板子能同时接D10-D13?
页:
[1]