Rudy,
Did you ever get the nRF8001 talking with your Teensy 3.1? I am having problems getting the echoDemo from Adafruit working. I am using a slightly different pinout than the example. Pin 9 for RDY is capable of interrupt on the Teensy, but I'm not sure if I need to do anything special to enable it.
I am watching all the SPI pins on a logic analyzer, and I can see a valid "device started" event after a reset (x01, x04, x81, x02, x00, x02). Nothing else ever happens over the SPI bus after that first traffic, though. Let me know if this is similar to your issue. If not, I'll post in another thread.
I should also mention for completeness that I pulled the regulator off the Bluefruit LE board my nRF8001 is on, and I am supplying 3.3V from the Teensy. I am pretty sure this is working fine since I can see the initial traffic. It is the Teensy's turn to talk, and it has 2 data credits available per the nRF8001, but nothing else happens over the SPI to continue the setup procedure.
Thanks,
- Jarrod
Code:
/*********************************************************************
This is an example for our nRF8001 Bluetooth Low Energy Breakout
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/1697
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Kevin Townsend/KTOWN for Adafruit Industries.
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in any redistribution
*********************************************************************/
// This version uses the internal data queing so you can treat it like Serial (kinda)!
#include <SPI.h>
#include "Adafruit_BLE_UART.h"
// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10
//#define ADAFRUITBLE_RDY 2 // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RDY 9 // This should be an interrupt pin, on Uno thats #2 or #3
//#define ADAFRUITBLE_RST 9
#define ADAFRUITBLE_RST 17
#define MEMCS_N 22
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
/**************************************************************************/
/*!
Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{
pinMode(MEMCS_N, OUTPUT);
Serial.begin(9600);
delayMicroseconds(300000); // Delay added so serial message shows up on monitor after reset
Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Print echo demo"));
BTLEserial.begin();
}
/**************************************************************************/
/*!
Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;
int printmessages = 0;
void loop()
{
digitalWrite(MEMCS_N, HIGH); // hold the memory CS_N high to avoid bus contention
// Tell the nRF8001 to do whatever it should be working on.
BTLEserial.pollACI();
if (printmessages < 10) {
Serial.print(printmessages,DEC);
Serial.print(" Last status = 0x");
Serial.print(laststatus, HEX);
Serial.print(F("\n"));
printmessages++;
}
// Ask what is our current status
aci_evt_opcode_t status = BTLEserial.getState();
// If the status changed....
if (printmessages < 10) {
Serial.print(F("Status = 0x"));
Serial.print(status, HEX);
Serial.print(F("\n"));
//delayMicroseconds(1000000);
}
if (status != laststatus) {
// print it out!
if (status == ACI_EVT_DEVICE_STARTED) {
Serial.println(F("* Advertising started"));
}
if (status == ACI_EVT_CONNECTED) {
Serial.println(F("* Connected!"));
}
if (status == ACI_EVT_DISCONNECTED) {
Serial.println(F("* Disconnected or advertising timed out"));
}
// OK set the last status change to this one
laststatus = status;
}
if (status == ACI_EVT_CONNECTED) {
// Lets see if there's any data for us!
if (BTLEserial.available()) {
Serial.print("* "); Serial.print(BTLEserial.available()); Serial.println(F(" bytes available from BTLE"));
}
// OK while we still have something to read, get a character and print it out
while (BTLEserial.available()) {
char c = BTLEserial.read();
Serial.print(c);
}
// Next up, see if we have any data to get from the Serial console
if (Serial.available()) {
// Read a line from Serial
Serial.setTimeout(100); // 100 millisecond timeout
String s = Serial.readString();
// We need to convert the line to bytes, no more than 20 at this time
uint8_t sendbuffer[20];
s.getBytes(sendbuffer, 20);
char sendbuffersize = min(20, s.length());
Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.println("\"");
// write the data
BTLEserial.write(sendbuffer, sendbuffersize);
}
}
}