Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Teensy2 + RFM12B board + Jeelib

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1

    Teensy2 + RFM12B board + Jeelib

    I'm trying to get a Teensy2 I got from here a while back working with an RFM12B kit from JeeLabs and using their RFM12 Arduino library. The library comes with a demo sketch(RF12Demo) that I've compiled and uploaded to the Teensy, as well as to a second Arduino Uno board and another RFM12B kit. I wired up the Uno as per the instructions here, and the sketch runs, outputs configuration and help text to the serial monitor, and takes commands to control the RFM12B module. The module uses an SPI interface so I hooked it up to the Teensy like so. When I run the sketch, the initial library configuration is printed to the serial monitor just like on the Uno, but the help text does not show up and the Teensy locks up in an infinite loop. I traced it down via successive serial prints in the RF12 library to where it is trying to establish SPI communication with the RFM12B module. It appears to be waiting for a reply from the radio module which never comes. To make sure I didn't have a bad radio module, I switched the modules in the Teensy and the Uno and the same problem occurred. The one in the Uno always works and the one in the Teensy always hangs. I'm new to SPI communication so I'm not sure where to start troubleshooting this. I'm fairly certain I've made the right connections for the module to use the Teensy2's hardware SPI:

    Radio Module > Teensy
    SPI clock (SCK) > Pin 2 (PB1 - SCLK)
    SPI data out (SDO) > Pin 4 (PB3 - MISO)
    SPI data in (SDI) > Pin 3 - (PB2 - MOSI)
    SPI select (SEL) > Pin 1 - (PB0 - SS)
    IRQ > Pin 6 (PD0 - INT0)

    Does anyone have an idea of where I'm going wrong here?

  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    7
    I know it's been a while, but I managed to get the Teensy 2.0 working with the JeeLib RFM12B driver. Thought I'd share what I did.

    There are both hardware and software changes necessary, though nothing major.

    On the hardware side, the default SS pin is actually PB6/Digital 15. This is inherited from the 32u4 config used by the driver for the leonardo. It is pretty readily changeable if you want to use the default pin. The Teensy 2 does breakout the default SS pin on the board, where the leo uses it for the rx led.

    On the software side, find this line in RF12.cpp:

    #elif defined(__AVR_ATmega32U4__) //Arduino Leonardo

    *Above* that line, add the following code to RF12.cpp:

    #elif defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY)

    #define RFM_IRQ 0 // PD0, INT0, Digital3
    #define SS_DDR DDRB
    #define SS_PORT PORTB
    #define SS_BIT 6 // Dig10, PB6

    #define SPI_SS 0 // PB0, pin 8, Digital0
    #define SPI_MISO 3 // PB3, pin 11, Digital3
    #define SPI_MOSI 2 // PB2, pin 10, Digital2
    #define SPI_SCK 1 // PB1, pin 9, Digital1

    I successfully tested the changes with OPTIMIZE_SPI both disabled (the default) and enabled.

    I do intend to check the lowpowerlab RFM12 library as well. If/when I get around to that, I'll post success or otherwise as a followup post.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Quote Originally Posted by pmscientist View Post
    I know it's been a while, but I managed to get the Teensy 2.0 working with the JeeLib RFM12B driver. Thought I'd share what I did.

    There are both hardware and software changes necessary, though nothing major.

    On the hardware side, the default SS pin is actually PB6/Digital 15. This is inherited from the 32u4 config used by the driver for the leonardo. It is pretty readily changeable if you want to use the default pin. The Teensy 2 does breakout the default SS pin on the board, where the leo uses it for the rx led.

    On the software side, find this line in RF12.cpp:

    #elif defined(__AVR_ATmega32U4__) //Arduino Leonardo

    *Above* that line, add the following code to RF12.cpp:

    #elif defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY)

    #define RFM_IRQ 0 // PD0, INT0, Digital3
    #define SS_DDR DDRB
    #define SS_PORT PORTB
    #define SS_BIT 6 // Dig10, PB6

    #define SPI_SS 0 // PB0, pin 8, Digital0
    #define SPI_MISO 3 // PB3, pin 11, Digital3
    #define SPI_MOSI 2 // PB2, pin 10, Digital2
    #define SPI_SCK 1 // PB1, pin 9, Digital1

    I successfully tested the changes with OPTIMIZE_SPI both disabled (the default) and enabled.

    I do intend to check the lowpowerlab RFM12 library as well. If/when I get around to that, I'll post success or otherwise as a followup post.

    Could you please post a link to the version of jeelib which did you use? I tried out to get JeeLib working with a Teensy 3.1. But on compiling I get the following error for the "rf12serial" demo sketch. :-(

    The RF12Demo Sketch fails to compile because the parity.h file is missing.

    Any ideas?

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Consider too, this software that supports many radios, many protocols, and AVR or Teensy2, Teensy3 or other Arduino-like boards

    http://www.airspayce.com/mikem/arduino/RadioHead/

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,491
    Quote Originally Posted by virusbrain View Post
    The RF12Demo Sketch fails to compile because the parity.h file is missing.
    Please give this a try. Copy it to hardware/teensy/cores/teensy3/util

    Please let me know if it works for you?
    Attached Files Attached Files

  6. #6
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Hi Paul,

    Quote Originally Posted by PaulStoffregen View Post
    Please give this a try. Copy it to hardware/teensy/cores/teensy3/util

    Please let me know if it works for you?
    Thanks! Its a little improvment. Now I will get these errors:

    Code:
    /usr/share/arduino/libraries/JeeLib/Ports.cpp: In member function 'void InputPlug::select(uint8_t)':
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:662:10: warning: unused variable 'mask' [-Wunused-variable]
         byte mask = 1 << (portNum + 3); // digitalWrite is too slow
              ^
    In file included from /usr/share/arduino/hardware/teensy/cores/teensy3/WProgram.h:15:0,
                     from /usr/share/arduino/hardware/teensy/cores/teensy3/Arduino.h:1,
                     from /usr/share/arduino/libraries/JeeLib/Ports.h:10,
                     from /usr/share/arduino/libraries/JeeLib/Ports.cpp:5:
    /usr/share/arduino/libraries/JeeLib/Ports.cpp: In static member function 'static void Sleepy::watchdogInterrupts(char)':
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1081:30: error: 'WDP3' was not declared in this scope
             mode ^= bit(3) | bit(WDP3);
                                  ^
    /usr/share/arduino/hardware/teensy/cores/teensy3/wiring.h:91:25: note: in definition of macro 'bit'
     #define bit(b) (1UL << (b))
                             ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1084:35: error: 'WDIE' was not declared in this scope
         byte wdtcsr = mode >= 0 ? bit(WDIE) | mode : 0;
                                       ^
    /usr/share/arduino/hardware/teensy/cores/teensy3/wiring.h:91:25: note: in definition of macro 'bit'
     #define bit(b) (1UL << (b))
                             ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1085:5: error: 'MCUSR' was not declared in this scope
         MCUSR &= ~(1<<WDRF);
         ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1085:19: error: 'WDRF' was not declared in this scope
         MCUSR &= ~(1<<WDRF);
                       ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1088:16: error: 'WDTCR' was not declared in this scope
     #define WDTCSR WDTCR
                    ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1090:9: note: in expansion of macro 'WDTCSR'
             WDTCSR |= (1<<WDCE) | (1<<WDE); // timed sequence
             ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1090:23: error: 'WDCE' was not declared in this scope
             WDTCSR |= (1<<WDCE) | (1<<WDE); // timed sequence
                           ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1090:35: error: 'WDE' was not declared in this scope
             WDTCSR |= (1<<WDCE) | (1<<WDE); // timed sequence
                                       ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp: In static member function 'static void Sleepy::powerDown()':
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1097:23: error: 'ADCSRA' was not declared in this scope
         byte adcsraSave = ADCSRA;
                           ^
    In file included from /usr/share/arduino/hardware/teensy/cores/teensy3/WProgram.h:15:0,
                     from /usr/share/arduino/hardware/teensy/cores/teensy3/Arduino.h:1,
                     from /usr/share/arduino/libraries/JeeLib/Ports.h:10,
                     from /usr/share/arduino/libraries/JeeLib/Ports.cpp:5:
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1098:21: error: 'ADEN' was not declared in this scope
         ADCSRA &= ~ bit(ADEN); // disable the ADC
                         ^
    /usr/share/arduino/hardware/teensy/cores/teensy3/wiring.h:91:25: note: in definition of macro 'bit'
     #define bit(b) (1UL << (b))
                             ^
    In file included from /usr/share/arduino/hardware/teensy/cores/teensy3/WProgram.h:11:0,
                     from /usr/share/arduino/hardware/teensy/cores/teensy3/Arduino.h:1,
                     from /usr/share/arduino/libraries/JeeLib/Ports.h:10,
                     from /usr/share/arduino/libraries/JeeLib/Ports.cpp:5:
    /usr/share/arduino/libraries/JeeLib/Ports.cpp: In member function 'void InputParser::poll()':
    /usr/share/arduino/hardware/teensy/cores/teensy3/avr/pgmspace.h:56:60: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     #define pgm_read_word(addr) (*(const unsigned short *)(addr))
                                                                ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1331:31: note: in expansion of macro 'pgm_read_word'
                     ((void (*)()) pgm_read_word(&p->fun))();
                                   ^
    /usr/share/arduino/hardware/teensy/cores/teensy3/avr/pgmspace.h:56:61: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     #define pgm_read_word(addr) (*(const unsigned short *)(addr))
                                                                 ^
    /usr/share/arduino/libraries/JeeLib/Ports.cpp:1331:31: note: in expansion of macro 'pgm_read_word'
                     ((void (*)()) pgm_read_word(&p->fun))();
                                   ^
    Looks like the JeeLib doesn't know the register?

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    7
    Quote Originally Posted by virusbrain View Post
    Could you please post a link to the version of jeelib which did you use? I tried out to get JeeLib working with a Teensy 3.1. But on compiling I get the following error for the "rf12serial" demo sketch. :-(

    The RF12Demo Sketch fails to compile because the parity.h file is missing.

    Any ideas?

    The patch posted really only applies to the Teensy 2 AFAIK. The jeelib RFM library really is pretty AVR specific at this point, I wouldn't expect it to work on the 3.x. FWIW, the jeelib I got this working with was from Oct 2012. It should work with any jeelib up until about Dec 2013 (when they started adding RFM69 code).

    For the RFM12 on Teensy 3.x, I'd reccomend taking a look here as a start. I would just call this a start though, I've had trouble with this library running for more than a few hours, and it hasn't been updated in a couple years.

    https://github.com/tht/T3Libs

    For the RFM69/22, the RadioHead library already mentioned is an excellent way to go, it's just too bad it doesn't have RFM12 support. That said, since the RFM69 is reccomended over the RFM12 by the manufacturer at this point and library support for the RFM69 seems much improved over the RFM12, I'd reccomend that for any new development. There's even a RFM69CW that has the same footprint as the RFM12, so if you've got a board designed for the older module, you're not necessarily stuck with it.

  8. #8
    Junior Member
    Join Date
    Oct 2014
    Posts
    1
    Quote Originally Posted by pmscientist View Post

    For the RFM12 on Teensy 3.x, I'd reccomend taking a look here as a start. I would just call this a start though, I've had trouble with this library running for more than a few hours, and it hasn't been updated in a couple years.

    https://github.com/tht/T3Libs
    I came across this thread as I am about to write an RFM12/69 library that among other things has a "packet level compatability" for Jeelib/RFM12/69, as well as meeting some other specific needs of my own (multi-SPI etc) for the T3.1.

    Anyhow - to the point - THT's T3 library above can suffer from a buffer overflow, which manifests itself when a large packet is attempted to be retrieved. The fix is a simple buffer protection statement. I'll fixup THT's lib tomorrow by posting a push request to his repo, and update a link back here. I am not saying there are not other issues with T3Libs but this fix will certainly get you more mileage....

  9. #9
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Quote Originally Posted by lightbulb View Post
    I'll fixup THT's lib tomorrow by posting a push request to his repo, and update a link back here. I am not saying there are not other issues with T3Libs but this fix will certainly get you more mileage....
    Has this topic moved elsewhere?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •