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.
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
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
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
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
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
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
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..?
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)
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().
Hi Corey,
Yes..C# lulled me into coding irresponsibly
I changed the code so that a pre-defined string[] was used in the loop. This of course solved the problem.
Cheers
Ganesh
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
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
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
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
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.
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
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..
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