View previous topic :: View next topic |
Author |
Message |
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Fri Dec 30, 2011 11:55 pm Post subject: RFM22B/RFM23B Bascom-AVR examples |
|
|
Here you find examples for RFM22B and RFM23B with Bascom-AVR
As already posted here
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=51175#51175
here is an example for using a RFM23B or RFM22B from Hope Rf with Atmega88
http://www.hoperf.com/rf_fsk/fsk/RFM23B.htm
Data rate = 56 kBps
Center Frequency = 868 Mhz (which you can adapt to your country settings according the excel calculator)
Excel Calculator was already posted here: http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=51085#51085
The RFM23B is based on the SI4431 from Silicon Labs so I used the different Silabs data sheets.
This example is using many of RFM22/23B included features like 64 Byte FIFO, header or CRC.
With the header the RFM22/23B is acting like a filter so you can define from which node address you want to receive date (e.g. only from address 1).
The only featue I missed with RFM23B is in my opinion data encryption/decryption.
Therefore this example also show the new XTEA encryption/decryption function of Bascom-AVR !
(It is also no problem to run this XTEA function with ATTINY variants of AVR’s because it is really tiny)
Code: | ' Transmit and Receive Packets Using the FIFO
' +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
' | P | P | P | P | 2D | D4 | HEADER|Length |Data 0 |Data 1 | .... |Data 63| CRC | CRC |
' +-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+-------+
' <-------32Bit Preamble-------- -><Sync. Pattern ><-Addr-> <----------Data (Payload)------><--16-Bit CRC--> |
In the example the transmitter is sending a string with 64 Byte to a receiver Node. The receiver node send back an Acknowledge (16 Byte) to the transmitter.
Terminal output of Transmitter:
Code: | --- RFM23B - ATMEGA88 ---
Device Type : 08
Device Version: 06
Node Address = 2
This Node receive from Address 1 and broadcast address (&HFF)
<Addr 2> receive from <Addr 1> Data = ACKNOWLEDGE ! / Length= 16 RSSI= 75 AFC Corr= 312.5 Hz
<Addr 2> receive from <Addr 1> Data = ACKNOWLEDGE ! / Length= 16 RSSI= 78 AFC Corr= 625.0 Hz
<Addr 2> receive from <Addr 1> Data = ACKNOWLEDGE ! / Length= 16 RSSI= 72 AFC Corr= 312.5 Hz
<Addr 2> receive from <Addr 1> Data = ACKNOWLEDGE ! / Length= 16 RSSI= 78 AFC Corr= 625.0 Hz
<Addr 2> receive from <Addr 1> Data = ACKNOWLEDGE ! / Length= 16 RSSI= 107 AFC Corr= 312.5 Hz
<Addr 2> receive from <Addr 1> Data = ACKNOWLEDGE ! / Length= 16 RSSI= 104 AFC Corr= 625.0 Hz |
Terminal output of Receiver:
Code: | --- RFM23B - ATMEGA88 ---
Device Type : 08
Device Version: 06
Node Address = 1
This Node receive from Address 2 and broadcast address (&HFF)
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 74 AFC Corr= 79687.5 Hz
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 75 AFC Corr= 79375.0 Hz
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 106 AFC Corr= 79375.0 Hz
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 74 AFC Corr= 79375.0 Hz
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 80 AFC Corr= 79375.0 Hz
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 76 AFC Corr= 79375.0 Hz
<Addr 1> receive from <Addr 2> Data= Hello Bascom Freaks !, This is 64 Byte Buffer sent out by RFM23B / Length= 64 RSSI= 76 AFC Corr= 79375.0 Hz
|
To find the right values for init of the RFM23B I used the Excel calculator from here:
http://www.hoperf.com/upload/rf/RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls
MAK3
Last edited by MAK3 on Sat Dec 31, 2011 12:01 am; edited 1 time in total |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Sat Dec 31, 2011 12:00 am Post subject: |
|
|
Hi,
here are examples for sending more than 64 Bytes.
The RFM23B FIFO is 64Bytes and when you want to send more bytes (up to 255) in one transmission task you need to refill the FIFO again with data and check special interrupts of RFM23B to make it work.
see attachment for examples.
The examples use the same include files I already posted with the first RFM23B examples. |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Sat Dec 31, 2011 3:23 am Post subject: |
|
|
Great work!
Just received the 22Bs. Will be a while before test...will make a couple of test boards first.
Am interested in getting maybe close to the 250 kbaud with direct mode and a At168 at 24MHz for higher SPI speed.
Maybe without header but with variable sync bytes. And the frequ. will be 915 MHz.
Can't play at your speed...too much other stuff going on....called work...haha.
Have a great NEW YEAR.
Hubert |
|
Back to top |
|
|
AndersL
Joined: 25 Jan 2010 Posts: 92 Location: Kragerø,Norway
|
Posted: Mon Jan 02, 2012 10:17 pm Post subject: |
|
|
Hubert and MAK3:
I've found that my RFM22's are quit different from RFM22B (and RFM23B)
Its an older version and the registers for packet handler,header control etc are not the same.
Seems that I need to upgrade to the B version to follow MAK3's examples.
Anyhow, they are still usable
I bought mine from futurlec, but they dont have the B version.
May I ask where you bought yours?[/b] _________________ Anders |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Tue Jan 03, 2012 8:03 am Post subject: |
|
|
The first link gives some agents websites and locations worldwide.
The second link is where I bought my 915 MHz rfm22b-s2 in the USA (SMD-version....also the crystal).
The third is a website in Germany and they sell some versions.
Did not have a lot of luck with other searches.
http://www.hoperf.com/agent.htm
http://www.embeddedwirelesssolutions.com/default.html
http://www.octamex.de/shop/
There are probably others who sell the modules.
The rfm22b-s1 is still with the can-crystal, otherwise I think the same like the -s2.
Also get the one that is the right frequency for your country.
Although the chip can be programed for different frequencies, the antenna coupling would have to be changed.....all SMD and not worth the trouble otherwise you could just build from the chip and it would be more expensive than the module..
For my own tests I am making a couple of breakout boards with 3.3 V regulator
and with 5 V signal interface (simple TTL OC 7407) to the MCU, so I can test with higher SPI speeds.
The module seems to be able to do 10 MHz SPI.
Hope this helps a bit
Hubert
edit:
http://www.lynx-dev.com/
seem to offer quite a selection too. |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Tue Jan 03, 2012 9:51 am Post subject: |
|
|
Hello,
the RFM22 used SI4432 RevV2 where the RFM22B is using SI4432 Rev B (from Silicon Labs).
The difference can be found in AN457: Transitioning Si4432 from Rev V2 to Rev B
There was more changes in the registers.
http://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support%20Documents/TechnicalDocs/AN457.pdf&src=SupportDocLibrary
The RFM23 used Si4431-A0 and the RFM23B use Si443x-B1
Quote: | The Si443x-B1 is the latest production revision. All the errata items of Si4431-A0 and Si4432-V2 are corrected on this silicon. |
For my examples I used: RFM23B-868-S1
MAK3 |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Wed Jan 04, 2012 6:38 am Post subject: |
|
|
@MAK3,
thanks for the link. It is a nice board.
I took a look at it and think that it works off the internal OSC.
Anyway, I do not have a problem with smd or double sided for testboards.
Reason for self made board: speed at 24 MHz with at least 6 MHz SPI.
That means that the MCU has to run at 5 V.
The exercise is to get as much speed out of it as possible to use it for my VTOL (with 5 AT168s).
I want to get as close as possible to the advertized 256 Kbaud with direct mode. I know that in reality it will not be possible for that data speed with all the handling involved.
An other thought would be multiple channels of operation with frequency hopping to combine it for a higher data rate.
It would still be cheaper (hardware) and more easily implemented than other high speed options that do not have the range of this module.
The processor also has to do the CRC since in direct mode it is not available "on chip".
I also want to wait for the next release of Bascom and implement encryption.
It drags on but I rather wait for what I want it to do and be able to do it. Transmit all vital data from the VTOL to the base.
There are some systems available but not really what I want.
This is the reasoning why I designed my own RC-receiver pulse reader and RC-servo controller.
It will take a bit of time to test but like mentioned before, work has priority.
Thank you again for the great link.
Hubert |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Wed Jan 04, 2012 1:48 pm Post subject: |
|
|
Quote: | It will take a bit of time to test but like mentioned before, work has priority.
| That's ok. Take your time.
But what you trying to accomplish is crying for an ATXMEGA16A4-AU (TQFP 44).
You want to overclock an atmega168 (24 Mhz) where you get 32MHz without external Osci with ATXMEGA16A4.
For 20MHz and more with atmega168 you need 5V for Atmega168 but 3.3 for rfm22b so you need two different voltage regulator where you just need one with atxmega (3.3V)
And in addition you need a voltage converter between a atemga168 and rfm22b (5V----3V).
To get close to or meet the 256kbps you could use DMA with ATXMEGA. I already used it with a serial interface so it will work also for spi interface.
And last but not least with an ATXMEGA16A4-AU you get 2 times more SRAM compared to an atmega168. You need large buffers to feed the rfm22b with 256kbps and receive this amount of data so more SRAM is also nice to have.
My examples use atmga88 but my next pair of rfm23b will be connected to ATXMEGA16A4-AU so I will post my examples as ATXMEGA variants.
MAK3 |
|
Back to top |
|
|
AndersL
Joined: 25 Jan 2010 Posts: 92 Location: Kragerø,Norway
|
Posted: Wed Jan 04, 2012 3:17 pm Post subject: |
|
|
Hi MAK3 and Hubert,
thanks for the links. I bought a handfull RFM22B's from http://www.lynx-dev.com/.
I had a close look trough the errata and Transitioning pdf's and my old RFM22's seems to be close enough to the B version
to work.
After some debuging i found that my RFM22's dont accept the write from: sub Rf23b_write.
When I read the regs after an init, all regs are default.
Using my previous testcode they all function well.
This dosent work:
Code: | Sub Rf23b_write(byval Addr As Byte , Byval Value As Byte)
Reset Nsel ' RFM23B Slave Select
Set Addr.7 'Set write bit
Spiout Addr , 1 ' Write Address
Spiout Value , 1 ' Write Data Byte
Set Nsel
End Sub |
This work:
Code: | Sub Rf22_write(byval Wr As Word) As Word
Cmd(2) = Low(wr) 'low byte
Cmd(1) = High(wr) 'high byte
Set Cmd(1).7 'set Write bit
Reset Nsel
Spiout Cmd(1) , 2
Set Nsel
End Sub |
It beats me how this could be the case
Anyboy knows why?
This is also why I could'nt get the teperature reading to work. _________________ Anders |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Wed Jan 04, 2012 6:01 pm Post subject: |
|
|
@MAK3,
one of the early datasheets of 48/88/168 stated the following:
• Speed Grade:
– ATmega48V/88V/168V: 0 - 6 MHz @ 1.8 - 5.5V, 0 - 12 MHz @ 2.7 - 5.5V
– ATmega48/88/168: 0 - 12 MHz @ 2.7 - 5.5V, 0 - 24 MHz @ 4.5 - 5.5V
Atmel must have had their own internal reasons to change the specs.
Have not had a problem with it ever.
The MCU is not included in the test board so that I can connect it to any MCU with any supply up to 5V,
with or without level conversion. And yes, ATXMEGA is probably best for the final versions (got a bunch of them).
The AT168 right now is the choice because with the PU-DIP-vers. I can tinker on the test-boards and have quite a few available.
The high data transfer speed for me is only interesting for a low data count of 32 to 48 bytes at a time at refresh repeat times of about 40 to 50 times a second. Fast data burst leaves time in between to do calculations.
The average data volume over the link might be 2 Kbytes/sec.
The thought is also to not use a return confirmation and eliminate switching of RX/TX but use CRC to accept or dismiss the data burst.
Hubert |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Wed Jan 04, 2012 8:25 pm Post subject: |
|
|
@AndersL
ok you use both sub call's as By value and not by Ref.
Please check what is the content of Addr and Value before they will be sent out by Spiout.
For example is the Write bit (Bit 7) really set after Set Addr.7 ?
See code:
Code: | Sub Rf23b_write(byval Addr As Byte , Byval Value As Byte)
Reset Nsel ' RFM23B Slave Select
Set Addr.7 'Set write bit
print bin(Addr) '<<<<<--------
print bin(Value) '<<<<<--------
Spiout Addr , 1 ' Write Address
Spiout Value , 1 ' Write Data Byte
Set Nsel
End Sub |
MAK3 |
|
Back to top |
|
|
AndersL
Joined: 25 Jan 2010 Posts: 92 Location: Kragerø,Norway
|
Posted: Wed Jan 04, 2012 9:13 pm Post subject: |
|
|
@MAK3,
You're right. The write bit (Addr.7) is not set.
The sub and the rest of the code is a copy of your example, and its working for you....?
Since the variable is passing byval, it shouldbe editable inside the sub (without changing the original).
??
Btw:I'm running this in a mega328p. _________________ Anders |
|
Back to top |
|
|
AndersL
Joined: 25 Jan 2010 Posts: 92 Location: Kragerø,Norway
|
Posted: Wed Jan 04, 2012 9:28 pm Post subject: |
|
|
@MAK3, btw, just programmed your testcode with modfication for the sub and the corrections
mentioned in the errata, and its working like a charm _________________ Anders |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Wed Jan 04, 2012 10:52 pm Post subject: |
|
|
@AndersL
Quote: | You're right. The write bit (Addr.7) is not set. |
Which version of Bascom-AVR do you use ?
Quote: | @MAK3, btw, just programmed your testcode with modfication for the sub and the corrections
mentioned in the errata, and its working like a charm |
Good to know. Thanks.
MAK3 |
|
Back to top |
|
|
|