[SOLVED] Yet another RFM69HCW / W5100 ethernet gateway thread :-)



  • Hi all,

    I'm working on moving my very modest (two sensors) mysensors environment to the RFM69 radio and 2.1.1. of the libraries.

    Setup:

    • Arduino Uno R3
    • Adafruit RFM69HCW breakout board (powered by the 5V from the Arduino)
    • W5100 shield (not module) for the Arduino - so I can't move pins around on the shield for any SPI conflicts

    this same combination worked fine with the NRF radio (i.e. same board, same Ethernet shield)

    for pins, I have the radio connected this way:

    • SCK - pin 13
    • MISO - pin 12
    • MOSI - pin 11
    • CS - pin 5
    • RST - pin 6
    • G0 (which is DI00) - pin 2

    additionally, just for completeness:

    • pin 3 is connected to an inclusion button
    • pins 7 - 9 are connected to LEDs

    this is a picture of my setup:

    gw setup

    and here is the sketch (with the intro and license stuff at the top removed for brevity):

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_RFM69
    //#define MY_RFM69_FREQUENCY RF69_433MHZ  // Define for frequency setting. Needed if you're radio module isn't 868Mhz (868Mhz is default in lib)
    #define MY_RFM69_FREQUENCY RF69_915MHZ  // Define for frequency setting. Needed if you're radio module isn't 868Mhz (868Mhz is default in lib)
    #define MY_IS_RFM69HW  // Mandatory if you radio module is the high power version (RFM69HW and RFM69HCW), Comment it if it's not the case
    // #define MY_RFM69_NETWORKID 100  // Default is 100 in lib. Uncomment it and set your preferred network id if needed
    // #define RF69_IRQ_PIN 4  // Default in lib is using D2 for common Atmel 328p (mini pro, nano, uno etc.). Uncomment it and set the pin you're using. Note for Atmel 328p, Mysensors, and regarding Arduino core implementation D2 or D3 are only available. But for advanced mcus like Atmel SAMD (Arduino Zero etc.), Esp8266 you will need to set this define for the corresponding pin used for IRQ
    #define MY_RF69_IRQ_NUM 2 // Temporary define (will be removed in next radio driver revision). Needed if you want to change the IRQ pin your radio is connected. So, if your radio is connected to D3/INT1, value is 1 (INT1). For others mcu like Atmel SAMD, Esp8266, value is simply the same as your RF69_IRQ_PIN
    // #define RF69_SPI_CS 15 // If using a different CS pin for the SPI bus
    #define MY_RF69_SPI_CS 5 // If using a different CS pin for the SPI bus
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    //#define MY_SOFTSPI
    //#define MY_SOFT_SPI_SCK_PIN 14
    //#define MY_SOFT_SPI_MISO_PIN 16
    //#define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    //#ifndef MY_RF24_CE_PIN
    //#define MY_RF24_CE_PIN 5
    //#endif
    //#ifndef MY_RF24_CS_PIN
    //#define MY_RF24_CS_PIN 6
    //#endif
    
    // Enable to UDP
    //#define MY_USE_UDP
    
    #define MY_IP_ADDRESS 192,168,0,215   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    #define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    
    void setup()
    {
    }
    
    void loop()
    {
    }
    

    other than adding a few debug prints, I haven't touched any of the library code. I 'upgraded' to the released 2.1.1 library via the Arduino IDE UI

    This is what I get when I run the sketch. The 'plain' looking (i.e. non-mysensors') output is just debug statements I added to MyTransportRFM69.cpp and RFM69.cpp. I had seen on another thread that it might help to add code to pulse (low then high) the reset line at the top of the transportinit() function, which I'm doing (pin 6). Didn't help.

    0;255;3;0;9;MCO:BGN:INIT GW,CP=RRNGA--,VER=2.1.1
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSF:WUR:MS=0
    pulsing reset
    pulsing reset done
    slave select pin: 5
    Waiting for ready mode
    wait for ready mode timed out
    radio init failed
    0;255;3;0;9;!TSM:INIT:TSP FAIL
    0;255;3;0;9;TSM:FAIL:CNT=1
    0;255;3;0;9;TSM:FAIL:PDT
    0;255;3;0;9;TSM:FAIL:RE-INIT
    0;255;3;0;9;TSM:INIT
    pulsing reset
    pulsing reset done
    slave select pin: 5
    
    

    from my debug code, it appears to be failing here in radio.initialize() in RFM69.cpp

    	while (((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00) && millis()-start < timeout) {
    		yield();
    	} // wait for ModeReady
    	if (millis()-start >= timeout) {
    		Serial.println("wait for ready mode timed out");
    		return false;
    

    I have two radios (the other connected to a Nano)... I ran the Radiohead test RX sketch on the Nano, and ran the test TX sketch on this exact Uno setup (after updating the pins in the sketch to match my setup) and it worked fine, so I know the radios are good.

    I read this thread as a possible recommended fix, but it kind of goes back and forth between what was done, and undone, so I'm not sure what the resulting working configuration is πŸ™‚

    Any thoughts? Next steps for troubleshooting?


  • Mod

    rfm69 modules are not 5V tolerant...



  • the Adafruit breakout for RFM69HCW is... it has a built-in regulator and logic shifters.



  • Thanks for the response, though, and good catch. it's one of the reasons I choose the Adafruit breakout, it because it's 5V tolerant and I wanted to use my Uno, at least for now. I may switch to the W5100 module and a Mini or Nano in the future, though, but it'll be several weeks before the module gets here, and I wanted to get some practical experience w/ the RFM69


  • Mod

    take a look at newer version of mysensors library and use the new RFM69 driver and see if may solve



  • ok, will do - from here? https://github.com/mysensors/MySensors (which branch, development?)


  • Admin

    @stevebus

    as mentioned a lot of other places, W5100 doesn't play well with other devices that wants to share the SPI bus.

    Most designs are using the SS signal to select the W5100, unfortunately using this pin will pull the MISO line low, when the W5100 is de-selected, effectively disabling communication from other SPI devices reaching the mcu.

    Some are using SPI_EN, which has to be inverted to act as a "normal" chip select line..

    this application note for the W5100 page 3 describes the problem.



  • Ok, thanks for the info @tbowmo . I had seen the issue documented in threads, but thought folks had worked around it here. I just haven't been able to distill the different threads into "here's the fix" πŸ™‚ (assuming there is one). I believe others have this combination working, right?

    Is it still true that SoftSPI won't work with the RFM69 (as I've seen on other threads)? That would get us a separate MISO line, but I had read it didn't work with that radio yet.



  • BTW - meant to also say that I have a ENC28J60 module laying on my desk if it's easier to get it working alongside the RFM69 πŸ™‚


  • Hero Member

    Did you edit the w5100.h according to the instructions @jpaulin posted in the thread you linked to?

    The editing of w5100.h is different depending on with CS pin you use.
    As I use D9 for the radio

    #define MY_RF69_SPI_CS 9
    

    And pin D10 for the w5100 CS and edited the w5100.h like this:

    #else
    	  inline static void initSS()    { DDRB  |=  _BV(2); };
    	  inline static void setSS()     { cli(); PORTB &= ~_BV(2); };
    	  inline static void resetSS()   { PORTB |=  _BV(2); sei(); };
        #endif
    

  • Hardware Contributor

    @korttoma
    I remember i checked, in recent Mysensors lib, w5100+rfm69 on same hardware spi bus without any changes to the w5100 lib.. Isn't it working??


  • Admin

    @scalz said in Yet another RFM69HCW / W5100 ethernet gateway thread πŸ™‚:

    @korttoma
    I remember i checked, in recent Mysensors lib, w5100+rfm69 on same hardware spi bus without any changes to the w5100 lib.. Isn't it working??

    Depends on your W5100 module πŸ™‚


  • Hardware Contributor

    tested it with this module https://www.itead.cc/w5100-ethernet-network-module.html and a 8Mhz/3.3v arduino mini if i remember (so no level shifting needed in my case)


  • Hero Member

    My RFM69 EthGW is built on the 2.1.0 version of the MySensors library and back then the w5100 lib hack was required. I don't know what the case is with current available MySensors Lib versions. And I don't have additional hardware to test this on...


  • Mod

    I am waiting for some new w5100 shields and rfm69hw that I'll test



  • Hi guys,

    Thanks for all the responses! I had not made any edits to the w5100.h file because a) I thought I had read they had become unnecessary, and b) I wasn't sure what exact values to use. Does the W5100 shield use pin 10 for CS? (pretty sure it uses 10 for the Ethernet module and 4 for the SD card, which I don't use, but hadn't had time to research for sure yet)... I'm using this shield, not a module, so I can't change the wiring. I've ordered the module-based W5100, but it'll be early June before I get it.

    With that said, I wonder it it's an issue between mysensors and specifically the Adafruit breakout of the RFM69HCW? Just to test a different way, I quickly last night built a raspberry pi Ethernet gateway (so the W5100 isn't' involved) and I had the same problem with the radio (failed to init). The radio initializes and works fine with the tests here, so I believe the radios are good. They just don't seem to respond to either an Arduino-based gateway or the raspberry pi one. I've ordered a couple of 'bare bones" RFM69HCW radios to test with.

    --Steve



  • Hey guys,

    quick update: got this working, at least on the gateway side -- haven't tried hooking up a node yet, that's next... Once I confirm that works, I'll add SOLVED to the title of this. πŸ™‚

    For the gateway, I went digging through the new driver code, looking for things to try and adding some debug writes, and found the code in RFM69_Initialise() where, if MY_RFM69_RST_PIN is defined, it will reset the radio. I already had the RST line on the RFM69HCW wired up, and had previously (with the old driver) manually added code to do it, but it didn't help...

    But with the new driver from the dev branch (used by #define MY_RFM69_NEW_DRIVER) I just added

    #define MY_RFM69_RST_PIN 6

    to my sketch and now I get...

    0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RPNGA---,VER=2.2.0-beta
    0;255;3;0;9;26 TSM:INIT
    0;255;3;0;9;28 TSF:WUR:MS=0
    0;255;3;0;9;36 TSM:INIT:TSP OK
    0;255;3;0;9;39 TSM:INIT:GW MODE
    0;255;3;0;9;43 TSM:READY:ID=0,PAR=0,DIS=0
    0;255;3;0;9;46 MCO:REG:NOT NEEDED
    IP: 192.168.0.215
    0;255;3;0;9;1350 MCO:BGN:STP
    0;255;3;0;9;1353 MCO:BGN:INIT OK,TSP=1
    

    I had read somewhere that the Adafruit breakout normally pulls RST high and supposedly resets itself at power-on, but I guess that wasn't enough... Explicitly resetting the radio seems to have done the trick and may be required for the Adafruit RFM69HCW breakout.

    Going to see if I can get the raspberry pi GW working now, since my curiosity is piqued πŸ™‚

    Thank you all for the help and input!

    --Steve



  • Hey guys,

    Another update... and an admission :-).

    After playing with it some more, it looks like I mis-read the details on how the Adafruit breakout treats the reset pin. I hard connected it to ground and it now works without setting the RST_PIN define. Apparently we just need to explicitly pull the RST pin low (which makes sense). Having the 'define' set was doing that in code earlier.

    You do have to have the new drivers, but don't have to fool with the reset pin. The GW works in both Arduino and raspberry pi now.

    thanks for thinking through this with me.



  • Marking SOLVED - we are back in business. Thanks everyone!



  • Ok - apparently I don't know how to mark it as SOLVED πŸ™‚


  • Mod

    @stevebus click edit on your fist post in this topic. At the very top in the edit view you can update the topic subject.



  • done! Thanks @mfalkvidd


Log in to reply
 

Suggested Topics

  • 3
  • 15
  • 2
  • 3
  • 2
  • 2

19
Online

11.2k
Users

11.1k
Topics

112.5k
Posts