The last step to create a wireless node is to hook up the RFM radio. Here is what we’re after:
There are 4 signals and 2 power pins to connect (more can be added later, for pin interrupts):
RFM69CW | STM32F103 | BOTH |
---|---|---|
SSEL (NSS) | PA4 | +3.3V |
SCLK | PA5 | GND |
MISO | PA6 | |
MOSI | PA7 |
And here is the other side, all hooked up with thin “Kynar” wirewrap wire in this case:
It doesn’t matter which of the two ground pins on the RFM69CW you connect, either one is fine. Also, don’t forget to attach an antenna wire of about 82 mm to the ANT pin (for 868 MHz).
So much for the hardware. If you have no other RFM69 nodes already in operation, you’ll need to build a pair of these to try out actual wireless communication, of course.
To get all the software needed for the RFM69CW into the µC, and assuming you’re starting from scratch, the easiest will be to install a single “combined” image, containing Mecrisp Forth for the STM32F103 plus a slew of Forth definitions from theembello/explore/1608-forth/flib/ area, in particular theRF69 driver (which in turn depends on SPI words, etc):
- make sure you haveFolie ready on your machine (see the previous article)
- download the latestmf224-ztw.hex file (it’s a text file, but nevertheless gibberish)
- the file contains Mecrisp Forth 2.2.4 plus the pre-built “Zero To Wireless” demo code
- go through the steps described before to put the board in “boot mode”
Now launch Folie as follows: folie -p <comport> -u mf224-ztw.hex
If all went well, the output will be similar to this (add the -v
flag to see
more):
$ folie -p /dev/cu.usbserial-A8009L2N -u mf224-ztw.hex
Connected to: /dev/cu.usbserial-A8009L2N
File: mf224-ztw.hex
Count: 32768 bytes (converted from Intel HEX)
Checksum: c0574666 hex
Synchronise: .+ OK
Boot loader: 22 hex
Chip type: 0410 hex - STM32F1, performance, medium-density
Unprotect: OK
Resume: .+ OK
Mass erase: OK
Uploading: ++++++++++++++++++++++<etc>++++++++++++++++++++++ OK
$
Good, almost there! Just restore the BOOT0 jumper to “0” and press reset. If you
now connect again with Folie in normal mode, and type “reset
”, this is what
should appear:
$ folie -p /dev/cu.usbserial-A8009L2N
Connected to: /dev/cu.usbserial-A8009L2N
ok.
reset ?Mecrisp-Stellaris 2.2.4 for STM32F103 by Matthias Koch
64 KB <ztw> 32a92103
Those last two lines are the key: Mecrisp reports its version, platform, and
creator on one line, and then the auto-launched init
word prints a second
line with some more tidbits:
- the chip has been identified as containing 64 KB of flash memory
- the wordset currently in flash corresponds to the “Zero To Wireless” demo fromhere
- a 32-bit hex “name” for the chip, derived by xor-ing this chip’s 96-bit unique hardware ID
If you type “list
”, you will see a dump of all the words currently
defined on your board.
At this point, the board is working, Mecrisp is working, and there’s a bunch of Forth code in flash, ready to serve you. The next step is to find out whether the RFM69 radio is also working.
Type “rf69-init
” to initialise SPI and the radio (using net group 42 @
868.6 MHz defaults):
rf69-init ok.
Now type “rf69.
” (with the period at the end) to get a listing of the radio’s
internal registers:
rf69.
0 1 2 3 4 5 6 7 8 9 A B C D E F
00: -- 04 00 02 8A 02 E1 D9 26 40 41 60 02 92 F5 20
10: 24 9F 09 1A 40 B0 7B 9B 08 4A 42 40 80 06 1C 00
20: 00 00 00 02 FF 00 07 80 00 A0 00 00 00 05 88 2D
30: 2A 00 00 00 00 00 00 D0 42 00 00 00 8F 12 00 00
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00
50: 00 01 88 08 00 00 01 00 1B 09 55 80 70 33 CA 08 ok.
Excellent - we’re seeing all sorts of settings. You could look them up in the HopeRF RFM69 datasheet, if you’re so inclined…
Now the tricky bit: as we all know, wireless needs (at least) two to tango!
- set up a second node, then launch Folie a second time using that
other serial port
- … or skip this step, if you have other nodes already sending data out
- verify that the second node also works and produces a good
rf69.
register dump
- now turn the first node into a listener, by typing:
rf69-listen
- this starts a loop which waits for incoming packets and reports each one
- that loop will continue to run until any command (or a return) is entered
- on the second node, type:
12345 rf69-txtest
- this will send out a single packet, with “
12345
” converted to ASCII bytes
- this will send out a single packet, with “
If all goes well, the first node should now report a new incoming packet:
RF69 21EE2A7C040022801805 3132333435
^^ ^^ ^^^^^^^^^^
| | |
group 5 bytes payload
Bingo! Lift-off! Wireless! Communication! Magic! Drumroll!
To select a different net group or frequency, you can adjust these variables:
123 rf69.group ! ok.
8683 rf69.freq ! ok.
Well, that’s the ideal case anyway. If for any reason this is not immediately working for you as expected, please consider registering and posting on theJeeLabs Forum or submitting an issue on GitHub. This code is still very young - getting it working under all circumstances (especially from Windows), is bound to take some more effort and detective work.
Still… it’s worth pointing out that we only needed two files to get a complete RF69 development environment going: the Folie serial utility, and the latest firmware hex dump. Once that works, everything else can be done in Forth, including reloading updated versions of the code in flash.