
Originally Posted by
lynton
I'll also have another look at SdFat, I only tried that very briefly and then moved to SD, but since SD is just a wrapper for SdFat it seems odd that it should fail.
SdFat still does not work, tested again with all of Pauls updates and with various settings for
#define ENABLE_SPI_TRANSACTION 1
#define ENABLE_SPI_YIELD 1
setting these on or off makes no noticeable difference, the registered nrf callbacks stop working after the SD card is accessed.
tested using the original posted code but with different pins posted again below for completeness.
Code:
#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#include <SdFat.h>
#define ADAFRUITBLE_REQ 22
#define ADAFRUITBLE_RDY 23
#define ADAFRUITBLE_RST 9
Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
const uint8_t chipSelect = 3; //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! */
delay(1000);
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;
}