Hey burner,
so this spiked my interest since I'm currently evaluating a esp8266 based gateway. I looked at your stuff and then - just to make sure I don't invest too much time in the native esp8266 route if an Arduino approach might work - I compiled RFM69.cpp as is for the esp8266.
I wired a rfm69hw to the esp HSPI port and DIO0 to D2. Then in RFM69.cpp:
#define RF69_IRQ_PIN D2
#define RF69_IRQ_NUM D2
In select() instead of MODE0 I used:
SPI.setDataMode(SPI_MODE0);
And finally I thew out the SPI config caching in select and unselect.
To my absolute astonishment with these three changes it just worked. I have a gateway sketch running and it's perfectly showing incoming packets. With an RSSI much better than I ever got on the Pi. Even though this is all on a breadboard.
So I guess this raises the question why a native port?
Joe
In select() instead of MODE0 I used:
SPI.setDataMode(SPI_MODE0);
"SPI.setDataMode(SPI_MODE0);" is the code that's already there. Did you mean SPI_MODE1? I have confirmed (https://github.com/esp8266/Arduino/blob/master/libraries/SPI/SPI.h) that:
const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0
const uint8_t SPI_MODE3 = 0x11; ///< CPOL: 1 CPHA: 1
That is the same as Table 19-2 (SPI Modes) in the atmega328p datasheet. However, the SX1231H datasheet (page 44) says, "The SPI interface gives access to the configuration register via a synchronous full-duplex protocol corresponding to CPOL = 0 and CPHA = 0 in Motorola/Freescale nomenclature. " Therefore, isn't the existing SPI_MODE0 parameter used in SetDataMode already correct?
And finally I thew out the SPI config caching in select and unselect.
By that, do you mean deleting
_SPCR = SPCR;
_SPSR = SPSR;
from select(), and deleting
SPCR = _SPCR;
SPSR = _SPSR;
from unselect()? I guess those were there to handle interrupt contention between the RFM69 and the SPI flash memory, which no longer exists.
+1 using makeEspArduino.mk instead of the Arduino IDE, there is also https://github.com/sudar/Arduino-Makefile.git for AVR-based boards. I made two small local changes to make my life a lot easier (on linux, might work on OSX, don't know about Windows). First I removed the hardwired ck upload option and made it a variable so the makefile works with a variety of boards
#
# UPLOAD_BOARD choices are none|ck|wifio|nodemcu
#
UPLOAD_BOARD ?= ck
...
upload: all
$(ESP_TOOL) $(UPLOAD_VERB) -cd $(UPLOAD_BOARD) -cb $(UPLOAD_SPEED) -cp $(UPLOAD_PORT) -ca 0x00000 -cf $(MAIN_EXE)
Second is I determine the appropriate USB port dynamically:
UPLOAD_PORT ?= $(shell lastusb)
Here is the lastusb script. This is the part that is linux specific for now:
#!/bin/bash
ls -1tr /dev/ttyUSB* | tail -1
I tend to have lots of Moteinos, Arduinos, ESP8266's and STM32's all plugged in at once. Keeping track of which was associated with which USB port was a real headache until Steve Childress pointed me to a powered USB hub with switchable ports. This is the one I've been using, I'm sure there are others that work just as well http://www.amazon.com/gp/product/B007WTHGL8 . When you want to upload to a particular device just toggle the associated switch, wait a couple of seconds for udev to do its thing and run "make upload" to upload to the most recently power cycled device. One of the biggest timesavers I've found.
Forgot to mention that if you are using a Moteino or other Arduino with built-in USB that implements a modem interface the following should work with those devices as well:
#!/bin/bash
ls -1tr /dev/tty{ACM,USB}* 2>/dev/null | tail -1
I wired it up with the above using the RFM69 example node code, but although the ArduinoOTA part appears as though it may be working, it's getting stuck in the RFM69 part. After a while, the WDT times out, causing a reboot loop:
Ready
IP address: 192.168.3.244
Transmitting at 915 Mhz...
Sending[1]: 1
Soft WDT reset
ctx: cont
sp: 3ffeff50 end: 3fff0210 offset: 01b0
>>>stack>>>
3fff0100: 00000001 3ffef038 3ffeeebc 00000001
3fff0110: 00000027 3ffef038 3ffeeebc 402052cd
3fff0120: 00000000 3ffeeebc 00000001 402054af
3fff0130: 3ffe8370 00000001 3ffeeebc 402058f0
3fff0140: 0000003d 00000001 3ffeeebc 000003e7
3fff0150: 3ffe8370 00000001 3ffeeebc 40205b85
3fff0160: 00000546 00000001 00000001 402076b0
3fff0170: 00000009 40105c5f 3ffef1f0 00000001
3fff0180: 00000001 3ffeeebc 00000000 4020521f
3fff0190: 3ffe8370 00000001 00000002 00000028
3fff01a0: 3ffeeed4 3ffeeebc 3ffef120 00000001
3fff01b0: 3ffeeec8 3ffeeebc 3ffef120 40202984
3fff01c0: 3ffe8370 7a684d20 002e2e2e feefeffe
3fff01d0: feefeffe feefeffe feefeffe 3ffef1dc
3fff01e0: 3fffdad0 00000000 3ffef1d5 402029d7
3fff01f0: 3fffdad0 00000000 3ffef1d5 40206cb4
3fff0200: feefeffe feefeffe 3ffef1f0 40100958
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
Booting
Ready
IP address: 192.168.3.244
Transmitting at 915 Mhz...
Sending[1]: 1
Soft WDT reset
Maybe I'm missing a pull-up or a pull-down resistor somewhere...?
12. SPI_MISO
13. SPI_MOSI
14. SPI_CLK
15. SPI_SS
You've got to use the HSPI port. It's D5-D8 on NodeMCU 1.0.
Other than that I'm not doing anything special. I initialize the SPI bus with
SPI.begin();
SPI.setDataMode( SPI_MODE0);
SPI.setBitOrder( MSBFIRST );
SPI.setClockDivider( SPI_CLOCK_DIV2 );
But that's it. Works amazingly well.
I've found that a clean way to modify the rfm69.h file for the ESP8266 pin definitions is to couch it this way:
#elif defined(ESP8266)
#define RF69_IRQ_PIN D2 // needed for esp8266
#define RF69_IRQ_NUM D2 // needed for esp8266
#define LED 2 // LED on ESP12F is on GPIO2
Having issues compiling. Ideas?
EDIT:
I am trying 1.5.2
make[2]: Leaving directory '/opt/esp-rfm69/app/spiffs'
/opt/esp-open-sdk/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -I/opt/esp-rfm69/sdk-overrides/include -I/opt/esp-open-sdk/sdk/include -Wl,--gc-sections -Wl,-Map=mapfile -nostdlib -T/opt/esp-rfm69//ld/eagle.app.v6.ld -Wl,@/opt/esp-rfm69//ld/defsym.rom -Wl,--no-check-sections -Wl,--wrap=_xtos_set_exception_handler -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lphy -lpp -lnet80211 -lwpa -lwpa2 -lmain -ljson -lsmartconfig -lssl -lcrypto user/.output/eagle/debug/lib/libuser.a json/.output/eagle/debug/lib/libjson.a platform/.output/eagle/debug/lib/libplatform.a libc/.output/eagle/debug/lib/liblibc.a http/.output/eagle/debug/lib/http.a dns/.output/eagle/debug/lib/dns.a driver/.output/eagle/debug/lib/libdriver.a lwip/.output/eagle/debug/lib/liblwip.a mqtt/.output/eagle/debug/lib/mqtt.a rfm/.output/eagle/debug/lib/rfm.a smart/.output/eagle/debug/lib/smart.a util/.output/eagle/debug/lib/util.a spiffs/.output/eagle/debug/lib/spiffs.a -Wl,--end-group -lm -o .output/eagle/debug/image/eagle.app.v6.out
/opt/esp-open-sdk/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.5/../../../../xtensa-lx106-elf/bin/ld: .output/eagle/debug/image/eagle.app.v6.out section `.text' will not fit in region `iram1_0_seg'
collect2: error: ld returned 1 exit status
../Makefile:332: recipe for target '.output/eagle/debug/image/eagle.app.v6.out' failed
make[1]: *** [.output/eagle/debug/image/eagle.app.v6.out] Error 1
make[1]: Leaving directory '/opt/esp-rfm69/app'
Makefile:284: recipe for target '.subdirs' failed
make: *** [.subdirs] Error 2