Hi,
I have an issue when using Adafruit_nrf8001 and SdFat libraries together.
Both work fine on there own but when SDFat is used when bluetooth is in use then the Bloothtooth connection is lost and does not come back until the program is restarted. ie the device stops advertising and scanning fails to rediscover the device.
Hardware
Teensy 3.1
Adafruit nRF8001 Bluefruit breakout.
WIZ820 & SD Adapter (without the wiz820io installed)
tested with UART v2.0 on android nexus 7 tablet.
I have edited the adafruit callback echo demo to read filenames of an sd card when a 'K' is sent over the bluetooth uart.
Once the SdFat library is called the bluetooth connection is lost , the tablet disconnects and advertising is not restarted.
I am using the latest Adafruit_nRF8001 lib as updated by Paul recently as per this thread
http://forum.pjrc.com/threads/26804-connecting-nRF8001-to-Teensy-3-1?p=57983&viewfull=1#post57983
I don't know whether this is an issue with the SDFat library ( I have seen conversations between Paul and the author about SPI transactions for Teensy ) or perhaps just my lack of understanding of SPI code on Teensy.
I have the latest SdFat lib from here https://github.com/greiman/SdFat/
The SD adapter is not piggybacked to the teensy but just connected to the relevant pins, the adapter itself appears to work fine with or without nrf8001 so I presume this is not a wiring issue.
Any advise appreciated,
thanks,
lynton
I have an issue when using Adafruit_nrf8001 and SdFat libraries together.
Both work fine on there own but when SDFat is used when bluetooth is in use then the Bloothtooth connection is lost and does not come back until the program is restarted. ie the device stops advertising and scanning fails to rediscover the device.
Hardware
Teensy 3.1
Adafruit nRF8001 Bluefruit breakout.
WIZ820 & SD Adapter (without the wiz820io installed)
tested with UART v2.0 on android nexus 7 tablet.
I have edited the adafruit callback echo demo to read filenames of an sd card when a 'K' is sent over the bluetooth uart.
Once the SdFat library is called the bluetooth connection is lost , the tablet disconnects and advertising is not restarted.
I am using the latest Adafruit_nRF8001 lib as updated by Paul recently as per this thread
http://forum.pjrc.com/threads/26804-connecting-nRF8001-to-Teensy-3-1?p=57983&viewfull=1#post57983
I don't know whether this is an issue with the SDFat library ( I have seen conversations between Paul and the author about SPI transactions for Teensy ) or perhaps just my lack of understanding of SPI code on Teensy.
I have the latest SdFat lib from here https://github.com/greiman/SdFat/
The SD adapter is not piggybacked to the teensy but just connected to the relevant pins, the adapter itself appears to work fine with or without nrf8001 so I presume this is not a wiring issue.
Any advise appreciated,
thanks,
lynton
Code:
#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#include <SdFat.h>
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2
#define ADAFRUITBLE_RST 9
Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
const uint8_t chipSelect = 4; //SS;
SdFat sd;
SdFile file;
/**************************************************************************/
/*!
This function is called whenever select ACI events happen
*/
/**************************************************************************/
void aciCallback(aci_evt_opcode_t event)
{
switch(event)
{
case ACI_EVT_DEVICE_STARTED:
Serial.println(F("Advertising started"));
break;
case ACI_EVT_CONNECTED:
Serial.println(F("Connected!"));
break;
case ACI_EVT_DISCONNECTED:
Serial.println(F("Disconnected or advertising timed out"));
break;
default:
break;
}
}
/**************************************************************************/
/*!
This function is called whenever data arrives on the RX channel
*/
/**************************************************************************/
void rxCallback(uint8_t *buffer, uint8_t len)
{
Serial.print(F("Received "));
Serial.print(len);
Serial.print(F(" bytes: "));
for(int i=0; i<len; i++)
Serial.print((char)buffer[i]);
Serial.print(F(" ["));
for(int i=0; i<len; i++)
{
Serial.print(" 0x"); Serial.print((char)buffer[i], HEX);
}
Serial.println(F(" ]"));
/* Echo the same data back! */
uart.write(buffer, len);
// Triger card read if 'K" is in the buffer.
if (*buffer == 'K') {
get_sd_card_files();
}
}
/**************************************************************************/
/*!
Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
while(!Serial); // Leonardo/Micro should wait for serial init
Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Callback Echo demo"));
uart.setRXcallback(rxCallback);
uart.setACIcallback(aciCallback);
// uart.setDeviceName("NEWNAME"); /* 7 characters max! */
uart.begin();
}
/**************************************************************************/
/*!
Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
void loop()
{
uart.pollACI();
}
void get_sd_card_files()
{
char name[13];
Serial.println("Opening SD card to generate list");
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
// open next file in root. The volume working directory, vwd, is root
while (file.openNext(sd.vwd(), O_READ)) {
file.printFileSize(&Serial);
Serial.write(' ');
file.printModifyDateTime(&Serial);
Serial.write(' ');
file.printName(&Serial);
if (!file.isDir()) {
// Indicate a directory.
file.getFilename(name);
Serial.println(name);
}
file.close();
}
return;
}