Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

RFM12B Wireless module with Netduino Plus


  • Please log in to reply
24 replies to this topic

#1 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 26 April 2011 - 08:12 AM

Hello all, This is my first project with Netduino platform (using netduino plus variant) - I am trying to integrate the Hope RF's RFM12B module to netduino plus (there is are existing examples for Arduino, AVR etc.). I wrote my own .net mf library for this purpose so that it is easier to debug and change the low level functions. Everything works fine, except that the max baud rate achievable with Netduino plus is 2400 bps. The same code when tested on FEZ Cobra works fine for baud rate upto 115.2 kbps. My test setup: Trying to send 16 bytes. Netduino Plus (Tx) ------> FEZ (Rx) = Max 2400 bps FEZ (Tx) ----------> Netduino Plus (Rx) = Max 2400 bps Netduino Plus(Tx) --------> Netduino Plus (Rx) = Max 2400 bps FEZ (Tx) -----------> FEZ (Rx) = Max 115.2 Kbps. I tried to find out the difference between the two platforms and what seems to be a possible cause is that the netduino plus is slower when it comes to SPI clock frequency (200 kHz, as compared to 20 MHz of FEZ Cobra) and also the time required to accomplish an input port read (to check the RFM ready state) is appox 1.5 ms in netduino plus (as compared to 200 uS in FEZ). The slower read of the RFM's ready state results in longer time required to send the data payload. When only one or two bytes is the length of the payload, the netduino plus is able to send the packets at baud rate of 4800 bps max. Can this issue be really due to slower processing on Netduino? Thanks a lot for any help or pointers! Cheers Ganesh

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 April 2011 - 09:04 AM

The clock on the NXP chips is a bit faster than the Atmel SAM7X chips, but that shouldn't affect communication speeds much if any. SPI on Netduino is very fast, and you can use the UARTs well in excess of 115,200 bps. If you have some code which we can all look at and/or test, that would be a pretty good first step to helping sort out the issue. Welcome to the Netduino community, Chris

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 April 2011 - 09:13 AM

Netduino Plus(Tx) --------> Netduino Plus (Rx) = Max 2400 bps

over SPI? Since Netduino can only operate as SPI Master as far as I know (although with a bit of additional code that could be changed I suppose)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 26 April 2011 - 04:56 PM

Hi Chris, Stefan, First, the "Netduino Plus(Tx) --------> Netduino Plus (Rx) = Max 2400 bps" was supposed to mean the RFM module on two netduinos (the dotted line indicating the RF link). Sorry, that was not clear. I have attached the RFM library (it is still very prototype, I intend to to evolve it into a proper lib). The code is as follows: 1. On the Tranmitting Netduino, the library function transmit is called with 16 byte payload: <code> RFM12B rfmModule = new RFM12B(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D0, Pins.ONBOARD_LED); while (true) rfmModule.Transmit(new byte[] { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F }); </code> 2. On the Recieving Netduino, the code is as follows: <code> RFM12B rfmModule = new RFM12B(SPI.SPI_module.SPI1, Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D0, Pins.ONBOARD_LED); while (true) rfmModule.Recieve(); </code> 3. In the library, the SPI port is inited like: SPI.Configuration spiConfig = new SPI.Configuration(spiSelectPin, false, 0, 0, false, true, 1000, spiModule); _spiPort = new SPI(spiConfig); (Note: I have tried different clock speeds: from 50khz to 10000khz) 4. What I noticed using a logic analyzer is that the SPI clock freq is around 200Khz. And, the time taken to do the read of the RFM Int input (digital input) is around 1.5ms. 5. I am using firmware 4.1.1 beta. Thanks a lot for your interest and infos. It is a pleasure working with a group that is so alive! Cheers Ganesh

Attached Files



#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 April 2011 - 10:53 PM

Hi Ganesh, I think we're still a little bit too high-level to determine the issue here. A speed reduction of 98% generally won't be due to slightly slower SPI communication. Can you isolate the specific section of code that's performing so differently? If we can boil this down to, say, a dozen lines of code...that would make it much simpler to solve. BTW, where did you get your RF modules? Are there breakout boards available for them? We'd be happy to pick up a few and test them here in the lab... I think the modules are ~$7. Chris

#6 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 27 April 2011 - 05:55 AM

Hi Chris, I agree, the example code is too high level to determine anything. I am going to dig deeper to determine the cause - I will post the update. I got the RFM module from http://www.watterott...-S2-Transceiver (In the U.S, I guess www.sparkfun.com would be easier). I got the module and soldered wires to a set of header pins. Also Jeelabs has a board: http://jeelabs.com/p...ts/rfm12b-board Testing with just 2400bps, I think the RFM12B is a very nice hardware to achieve wireless (bidirectional) communication. Cheers Ganesh

#7 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 28 April 2011 - 07:21 PM

I could get further deep into the problem - the rate at which I can send the bytes via SPI seems to be limited - i.e. between two spi.WriteRead(..), it takes at least 350uS - which means that the maximum rate at which I can send multibyte packets to RFM is about 22857 bps. I presume that if I can reduce the lag between two spi writes then I can send data at higher rate... I will work on this further. Any pointers would be very helpful at this stage :) Cheers

Attached Files



#8 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 30 April 2011 - 06:51 AM

Success at last!

The problem was in the receive routine - and all because of some string operation for debug message.

for (int i = 0; i < 16; i++)
{
data[i] = (byte)RF12_RECV();
//dbg += data[i].ToString() + " ";
ChkSum += data[i];
}

The line dbg += data[i].ToString() + " "; takes 1.35 ms to execute!! This delays clearing up of the fifo buffer and gets overwritten by the next transmit.

Now need to look into why string operation takes such a long time. Any ideas here..?

Cheers

#9 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 01 May 2011 - 01:46 AM

Now need to look into why string operation takes such a long time. Any ideas here..?

There are two red flags here. First, because C# strings are immutable, any string append operation like that inside a loop is going to be quadratic in complexity due to the copies that are made to an ever-growing string. Second, byte.ToString() isn't especially cheap. You might find it illuminating to trace through all the string temporaries that are created in the course of running that loop. (assume the data is 10 20 30 40 ... 160)

iteration 0:

10.ToString() => "10"
"10" + " " => "10 "
"" + "10 " => "10 "

iteration 1:

20.ToString() => "20"
"20" + " " => "20 "
"10 "+ "20 " => "10 20 "

iteration 2:

30.ToString() => "30"
"30" + " " => "30 "
"10 20 " + "30 " => "10 20 30 "

etc etc etc. To avoid the quadratic complexity, you can use a StringBuilder kind of thing (or a fixed string[] array with a string.Concat at the very end); of course in that case you'll still have the cost of all the calls to byte.ToString().

#10 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 01 May 2011 - 07:20 AM

Hi Corey, Yes..C# lulled me into coding irresponsibly :rolleyes: I changed the code so that a pre-defined string[] was used in the loop. This of course solved the problem. Cheers Ganesh

#11 mikepo

mikepo

    Member

  • Members
  • PipPip
  • 29 posts

Posted 06 May 2011 - 02:12 PM

Hi Ganesh, could you post the version of yoru RFM12B library that you got working? I have a few of these modules as well and have used them with Arduino, now trying to used them on the NetDuino. Thanks, Mike

#12 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 06 May 2011 - 02:32 PM

Hi Mike, I have attached the current library. It is not finished - at the moment i am trying to find the settings for highest speed and also for highest range. With the configuration set now, you can achieve 5388 bps and range of approx 25m in a normal home enviroment (incl. a wall in between). So far, I am happy with it. I would have loved to see higher speeds working but then the limitation is the SPI module in netduino (not the spi clock rate, but the lag between two consequetive write operations - the RFM expects all bytes to be clocked in within the net baudrate period. you can have higher speeds but with smaller payload. Since the overhead bytes of preamble, sync and crc is already 9 bytes, it does not make sense to transmit less that 16 bytes just to achieve speeds higher than 5338 bps). I will refine the library with some property accessors etc. and then post the final version again. Meanwhile if you have any suggestions or comments please let me know. There is a nice tool to calculate the commands: http://www.kewlit.com/RFM12B/ Regards Ganesh

Attached Files



#13 jamescw

jamescw

    New Member

  • Members
  • Pip
  • 1 posts

Posted 23 June 2011 - 12:42 PM

Hi Ganesh, This is great work! I have been working with the Arduino RFM12B diver from JeeLabs for a while now, but I was raised on C# and would much rather code in it. Is this library packet compatible with the JeeLabs driver? I have a number of JeeNodes around the house all transmitting using the JeeLabs driver, would this library be able to successfully decode the packets so I can retive the payload? Thanks, James

#14 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 23 June 2011 - 01:12 PM

Hi James, It should work with the jeelabs node (it is basically the RFM12B on a nice board). I have not tried it, but my gut feeling is that it should work without problems. Let me know how it went if you try it out. Cheers Ganesh

#15 J Wilson

J Wilson

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts

Posted 31 July 2011 - 11:22 PM


I will refine the library with some property accessors etc. and then post the final version again. Meanwhile if you have any suggestions or comments please let me know. There is a nice tool to calculate the commands: http://www.kewlit.com/RFM12B/

Regards

Ganesh


Ganesh,

Just checking to see if you have finished the refinements on your library? I'm a newbie to netduino and have done some simple projects with lighting LEDs, etc. Have just purchased a couple of RFM12B chips and hope to get a couple of netduinos talking to each other.

Thanks,
J

#16 R.Ganesh

R.Ganesh

    Member

  • Members
  • PipPip
  • 12 posts
  • LocationSwitzerland

Posted 01 August 2011 - 07:02 AM

Hi Jason, I had done only some cosmetic changes to the code, but not really towards refining it. Since the functions were working fine, I have been too lazy to work on it (thats the curse of prototype code, remains a prototype). If you just need the basic functio of transmit/recieve and you are happy to set the parameters in the library code then you could put it to use wihtout much worries. The trouble with creating a generic library is that it needs to be tested out. Cheers Ganesh

#17 erisan500

erisan500

    New Member

  • Members
  • Pip
  • 1 posts

Posted 02 September 2011 - 05:52 PM

I've got some RFM12B's too, so if you need testers, count me in.

BTW, I tried your code with the JeeLabs node, but it doesn't seem to work, and it's due to the different way he initializes the RFM12B I think:
//Band:
#define RF12_433MHZ     1
#define RF12_868MHZ     2
#define RF12_915MHZ     3


void rf12_initialize (uint8_t id, uint8_t band, uint8_t g) {
    nodeid = id;
    group = g;
    
    spi_initialize();
    
    pinMode(RFM_IRQ, INPUT);
    digitalWrite(RFM_IRQ, 1); // pull-up

    rf12_xfer(0x0000); // intitial SPI transfer added to avoid power-up problem

    rf12_xfer(RF_SLEEP_MODE); // DC (disable clk pin), enable lbd
    
    // wait until RFM12B is out of power-up reset, this takes several *seconds*
    rf12_xfer(RF_TXREG_WRITE); // in case we're still in OOK mode
    while (digitalRead(RFM_IRQ) == 0)
        rf12_xfer(0x0000);
        
    rf12_xfer(0x80C7 | (band << 4)); // EL (ena TX), EF (ena RX FIFO), 12.0pF 
    //rf12_xfer(0x80E7);
    rf12_xfer(0xA640); // 868MHz 
    rf12_xfer(0xC606); // approx 49.2 Kbps, i.e. 10000/29/(1+6) Kbps
    rf12_xfer(0x94A2); // VDI,FAST,134kHz,0dBm,-91dBm 
    rf12_xfer(0xC2AC); // AL,!ml,DIG,DQD4 
    if (group != 0) {
        rf12_xfer(0xCA83); // FIFO8,2-SYNC,!ff,DR 
        rf12_xfer(0xCE00 | group); // SYNC=2DXX; 
    } else {
        rf12_xfer(0xCA8B); // FIFO8,1-SYNC,!ff,DR 
        rf12_xfer(0xCE2D); // SYNC=2D; 
    }
    rf12_xfer(0xC483); // @PWR,NO RSTRIC,!st,!fi,OE,EN 
    rf12_xfer(0x9850); // !mp,90kHz,MAX OUT 
    rf12_xfer(0xCC77); // OB1,OB0, LPX,!ddy,DDIT,BW0 
    rf12_xfer(0xE000); // NOT USE 
    rf12_xfer(0xC800); // NOT USE 
    rf12_xfer(0xC049); // 1.66MHz,3.1V 

    rxstate = TXIDLE;
    if ((nodeid & NODE_ID) != 0)
        attachInterrupt(0, rf12_interrupt, LOW);
    else
        detachInterrupt(0);
}

void rf12_onOff (uint8_t value) {
    rf12_xfer(value ? RF_XMITTER_ON : RF_IDLE_MODE);
}


#18 Jay75

Jay75

    New Member

  • Members
  • Pip
  • 7 posts

Posted 17 November 2011 - 08:50 PM

can anyone help with getting this code to work with JEENODE as Eric has outlined it doesn't seem to work.. at least some pointer if you can... thank you..

#19 dtcDev

dtcDev

    New Member

  • Members
  • Pip
  • 1 posts

Posted 12 April 2012 - 10:46 PM

Hello. Sorry, my English is so-so. I trying create app code for NetDuino Plus (FW 4.2). I take source code of RFM12B_Lib and put him at new class. Device is never set true at IRQ line. Looks like I am not corrected initialize RFM. Can anyone help me? Thanks

#20 elettrozero

elettrozero

    Advanced Member

  • Members
  • PipPipPip
  • 58 posts

Posted 26 May 2013 - 09:46 AM

Hi all, I'm getting into RFM12B with ND and Arduino trying to make communicate each other.

Thanks for the ND library so far, I'm making few adjustments in terms of setting up the radio taking some from Arduino lib version.

If anybody interested write a line I'll post updates.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.