Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
freto
 
Posts: 4
Joined: Fri Mar 23, 2012 8:31 am

Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by freto »

I am trying to compile the demo code of the ADAFRUIT_BLE_UART library. I am using a Mac, Arduino IDE 1.05 and latest Teensy versions. The library compiles with Arduino boards or Teensy 2, however with Teensy 3 I get the following error:

In file included from echoDemo.ino:19:0:
/Users/fred/Documents/Arduino/libraries/Adafruit_BLE_UART/Adafruit_BLE_UART.h:47:12: error: conflicting return type specified for 'virtual uint16_t Adafruit_BLE_UART::write(uint8_t)'
In file included from /Users/fred/Applications/Arduino.app/Contents/Resources/Java/hardware/teensy/cores/teensy3/Stream.h:24:0,
from /Users/fred/Applications/Arduino.app/Contents/Resources/Java/hardware/teensy/cores/teensy3/HardwareSerial.h:143,
from /Users/fred/Applications/Arduino.app/Contents/Resources/Java/hardware/teensy/cores/teensy3/WProgram.h:16,
from /Users/fred/Applications/Arduino.app/Contents/Resources/Java/hardware/teensy/cores/teensy3/Arduino.h:1,
from /Users/fred/Applications/Arduino.app/Contents/Resources/Java/libraries/SPI/SPI.h:15,
from echoDemo.ino:18:
/Users/fred/Applications/Arduino.app/Contents/Resources/Java/hardware/teensy/cores/teensy3/Print.h:53:17: error: overriding 'virtual size_t Print::write(uint8_t)'

I can't see anything wrong with the declaration of write in Teensy3 Print.h

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by paulstoffregen »

I took a quick look at this library. It has multiple problems.

These compile errors with print() and write() are the easy part. The library simply has the wrong types, which happen to work on 8 bit AVR. Arduino's Print.h uses "size_t" for return types on Print class functions, but this library incorrectly has "uint16_t". Easy to fix.

The not-so-easy problem in this library is this code in utility/hal_aci_tl.cpp:

Code: Select all

void toggle_eimsk(bool state)
{
  /* ToDo: This will currently only work with the UNO/ATMega48/88/128/328 */
  /*       due to EIMSK. Abstract this away to something MCU nuetral! */
  uint8_t eimsk_bit = 0xFF;
  for (uint8_t i=0; i<sizeof(dreqinttable); i+=2) {
    if (HAL_IO_RADIO_RDY == dreqinttable[i]) {
      eimsk_bit = dreqinttable[i+1];
    }
  }
  if (eimsk_bit != 0xFF)
  {
    if (state)
      EIMSK |= (1 << eimsk_bit);
    else
      EIMSK &= ~(1 << eimsk_bit);
  }
  else
  {
    /* RDY isn't a valid HW INT pin! */
    while(1);
  }
}
As you can see in the comment, the author knew this won't work on anything other than Arduino Uno.

I can try to craft a fix, but I don't have this hardware on-hand for testing.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by paulstoffregen »

I made a copy of the library with the easy stuff fixed.

https://github.com/PaulStoffregen/Adafruit_nRF8001

To go any further, someone from Adafruit involved in the development of this library really needs to get involved. I just don't fully understand some of the logic inside the m_rdy_line_handle() interrupt handler, especially this part:

Code: Select all

  detachInterrupt(1);  // TODO: why is this hard-coded to 1 ?!
                       // Should it be HAL_IO_RADIO_IRQ ?
Is that simply a programming error? Maybe it's leftover code from some earlier version? The examples have the RDY signals connected to pin 2, which is interrupt 0 on Arduino Uno. Pin 3 (interrupt 1) doesn't appear to be used at all, which leads me to believe this is simply a mistake.

But if this really is doing something important, which I just don't understand, there's no way I can offer any edits to this library until I fully understand why it's calling detachInterrupt().

Later in m_rdy_line_handle() it calls toggle_eimsk(false), but only conditionally based on the status of a queue. My guess is the author originally tried attachInterrupt and detachInterrupt, but reenabling with attachInterrupt probably clears the interrupt pending status, so the EIMSK register was used directly.

I can try to add support for Teensy 3.1 into this code, but first I really need to hear from soneone at Adafruit involved with this code. If detachInterrupt really is doing something important that I simply can't understand, I need to know before touching this code.

User avatar
freto
 
Posts: 4
Joined: Fri Mar 23, 2012 8:31 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by freto »

Thank you Paul for the effort, I learnt a few things anyway.
I could send you my board but I am on the other side of the ocean, and of course this device is sold out!

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by adafruit2 »

Thanks for the note - ktown is the author, and is still getting experience with Arduino-ese. paul, any help you can offer ktown is appreciated

User avatar
ktownsend
 
Posts: 1447
Joined: Thu Nov 05, 2009 2:18 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by ktownsend »

Hi Paul,

The current code is based on an internal port from Nordic, though I see they've made an updated version of the code public now. I agree it's completely UNO-centric and we should move to the latest version and fix what makes sense to make it a bit more standard/portable. I'll ping you about it over email.

K.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by paulstoffregen »

I ordered a couple of the breakout boards, now that they're back in stock.

They'll probably arrive sometime next week. I'll post here when I get them.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by paulstoffregen »

My nRF8001 breakouts haven't arrived yet, but Adafruit did ship them on Friday.

I started working on the code anyway. Here's preliminary fixes that at least let everything compile.

First, here's a patched copy of Adafruit_nRF8001. This fixes the return types for print(), println() and write().

https://github.com/PaulStoffregen/Adafruit_nRF8001

Then you'll need to update Teensyduino's core library. Here's the source code:

https://github.com/PaulStoffregen/cores

Just replace everything in hardware/teensy/cores with everything from this repository. That will fix the missing "avr/sleep.h" problem, and it adds a workaround for EIMSK.

This lets the library compile for Teensy 3.1. Of course, I can't actually test until the hardware arrives next week. But I have spent some time studying the library source code. I think there's at least some chance this might work.

If you give it a try, please let me know how this works for you?

User avatar
freto
 
Posts: 4
Joined: Fri Mar 23, 2012 8:31 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by freto »

Hello,
your code compiles but the BLE module does not work. The BTLEserial.begin() call returns True but the module "Advertising Started" does not appear and the module is not listed on my IPhone.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by paulstoffregen »

Thanks for giving it a try.

I still don't have the actual hardware, but Adafruit has shipped my order. Please keep following this thread. I hope to have a real solution in a week or so....

User avatar
kannan
 
Posts: 3
Joined: Thu Sep 12, 2013 4:36 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by kannan »

Hi Paul

Any luck on the updated code? Trying to move to a Teensy 3.1 from an Uno so any updates would be very much appreciated!

Thanks!

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by paulstoffregen »

The Adafruit package arrived.

At the moment, I'm crazy busy getting ready for Maker Faire. Honestly, I've kinda left most of the fabrication of these demos to the last minute (or last 2 weeks....) Odds are pretty much zero I'll have time to fiddle with this library or any others until after Maker Faire. Sorry, I'm just one guy with an overly-ambitious TODO list. ;)

However, something I have been working on recently (which is a big part of the reason I'm behind schedule on getting prepped for Maker Faire) is a contribution of the Arduino SPI library. This was mostly inspired by the trouble people have reported on the PJRC forum regarding the RF22 & RadioHead library (before this BLE board was released), but also by the design of this BLE library. The fundamental problem is Arduino lacks a way for multiple libraries to share the SPI bus. Combinations like SD and Ethernet work together because they never run from interrupts and they use identical SPI settings, so neither tries to access the SPI bus at the same time and either can still work after the other modifies the SPI settings.

These radio libraries, and CC3000, are a real problem. Even if it works alone, things are likely to go very wrong if it's used together with any other library that uses SPI. The problems happen on all boards, even Arduino Uno.

The Arduino Team seems to recognize this is a real and growing problem for Arduino as a platform (though it's taken quite a bit of effort to explain the issue and propose a solution). Over the last couple weeks, a LOT has happened towards a really great long-term solution. That's where a lot of my time has gone in these last couple weeks. In fact, there's the conversation.

https://groups.google.com/a/arduino.cc/ ... uZLfjeZjDI

Here you can see code I worked on recently, for the SPI transaction stuff: 10 commits from Apr 21-24, based on a lot of work before just those commits.

https://github.com/PaulStoffregen/Ardui ... /ide-1.5.x

I know all this bigger picture Arduino SPI stuff doesn't help you right now with this BLE module. This is one of 7 libraries I'm studying as part of this SPI compatibility stuff, so I absolutely will get it working on Teensy 3.1 soon, where "soon" is probably the first couple weeks of June, after Maker Faire. I'm sorry it's such a slow process.

Hopefully around that time frame, the Arduino Team will release Arduino 1.5.7 with this SPI transaction API.

tato123
 
Posts: 14
Joined: Tue Jan 21, 2014 12:02 am

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by tato123 »

I've made the updates necessary to run the Adafruit nrf8001 with the teensy3.1 and really any ARM board (as well as included compatibility with arduino and chipkit). It's based off the latest nordic sdk and includes preprocessor defs to switch between appropriate processors.

I've validated with the hello world included and was able to confirm that I can send data between the nrf UART app and the adafruit bluetooth breakout.

I'd be happy to create a pull request and update the adafruit code and examples as well so everyone can enjoy it. For now it can be found hosted on my github (I restructured the files so that it could be dropped directly into the arduino/libraries folder)

https://github.com/tato123/nrf8001_arm_support

User avatar
aaronpbrooks
 
Posts: 6
Joined: Wed Aug 07, 2013 1:09 pm

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by aaronpbrooks »

Thanks tato123! I am going to take a look and have a test run with your library this evening. I appreciate your efforts!!!

User avatar
aaronpbrooks
 
Posts: 6
Joined: Wed Aug 07, 2013 1:09 pm

Re: Teensy 3 + Adafruit nRF8001 BLE, library compile problem

Post by aaronpbrooks »

I did have a few minutes to try out your code, but not long enough to get it running on my Teensy.

I did a drag and drop of your master folder into the arduino library, but no dice. Are there additional steps that need to be taken to get it running?

Thanks again for the work! This is well beyond my capabilities.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”