SPI on Teensy 3.1, my code hangs

Status
Not open for further replies.

Vignesh

Member
Hello All,
I am trying to get the SPI working on Teensy 3.1 for RFM22B. Need help with my SPI driver.

Tried the SPI (I guess default lib) mentioned in www.pjrc.com, but it did not work.
So wrote my BitBanged SPI to test the h/w, and it worked, i.e. I could read the RFM22 Register.
Next, I tried the Fast SPI lib from Btmcmahan, Had to fix some Registers (like SPI_.. to SPI0_.. ), and map it to my SPI CS, but could not get it to work either :(

So, finally decided to write my own, ..but my code hangs when I initialize the SPI MCR register!!
i.e. when I write to register..
SPI0_MCR = 0x80000000;
(My heart beat LED stops blinking)

I have included header file
#include <mk20dx128.h>
#include <core_pins.h>

Just wanted to add, I am not sure if there is a specific way to include lib in Arduino. :confused:
i.e. I did not select "Sketch->Import Library->SPI" to import SPI lib, just included SPI.h file and invoked the SPI APIs but the code was not hanging, i.e. my heart beat LED blinks.

Do we need to enable the SPI core in the chip, or enable clocks to it ? Writing 0x0 to MCR register hangs, so I would guess there is no clocks to the SPI core where this (MCR) register is implemented.
Any help is appreciated.
Regards,
Vignesh
 
The Teensy 3.x library makes the Arduino SPI library interface work with the same user code. The differences between AVR (Arduino) and Teensyduino (ARM) hardware are hidden by an abstraction done in the Teensy library.

This excellent RFM22 library is running on my Teensy 3's. It supports a full protocol stack for reliable datagrams (like UDP), with star and mesh topologies. Amazing work.
http://www.airspayce.com/mikem/arduino/RF22/

As I recall, I made no changes to the library code.
I did alter the test/demo app that calls the library.

And I've been working with this library using Visual Micro as the IDE but the normal Arduino/Teeensyduino IDE will work too.
 
Last edited:
Hi Stevech,
Thanks a lot, that helped!! :)
In my case the SCK is on Pin#14 as LED is on 13 and I had to add this..
SPI.setSCK(14); // before the rf22.init()

Would like to add a few questions.. (about RFM22B)
I just tried rf22_test, and the code sets the freq to 434MHz in test_tx_pn9(), not sure if that is okay in US ?(http://www.ntia.doc.gov/files/ntia/publications/2003-allochrt.pdf) its said to be an Amateur and RadioLocation band.

My module (via sparkfun) is for 915MHz, I am assuming setFrequency() API is the right API for me to change the frequency ?
Would you be knowing what range can I expect in a typical apartment environment ?
Thanks and Regards,
Vignesh
 
433MHz is OK in the US but the FCC limits the transmitter duty cycle (ratio of on to off) to a small number.
902-928MHz is also unlicensed and is much less strict about duty cycles unless you run 2MHz bandwidth and 1Mbps or so. Then freq. hopping can make it legal.
Regulations get complex.

I urge you to use one of the RFM22 libraries and apps.

Range - antenna dependent. If you have an 8 in. wire for 433MHz, or a bit shorter (1/4 wavelength) for 900 MHz band, RFM22 will do line of sight outdoors of hundreds of feet. Indoors, excluding lath and plaster walls (drywall is common), perhaps 150 ft. through a 2-3 walls. All depends on placement, etc.
 
Last edited:
Thanks again Stevech!
Yes, I am impressed with RF22 Lib :) ..though not a fan of CPP in embedded environment, but it worked in my first attempt with it. So will be using this library.
Need to rig up the second circuit to test the range.. have at least 6 dry walls in between. I am using 1/4 wavelength monopole antenna as suggested on Sparkfun (about 8.3cms).
Regards,
Vignesh
 
Status
Not open for further replies.
Back
Top