Forum >How to set CS pin on Beetle BLE/Bluno Beetle to Adafruit SD Card Breakout - Initialization Failed!
How to set CS pin on Beetle BLE/Bluno Beetle to Adafruit SD Card Breakout - Initialization Failed!

Hi I have a Beetle BLE (https://www.dfrobot.com/wiki/index.php/ ... KU:DFR0339) and I am trying to connect an Adafruit MicroSD card breakout board+ (https://www.adafruit.com/product/254) via SPI connections. I am trying the following code, but I am having trouble selecting the CS pin using D4 since the Beetle has no D10. Does anyone know if I am selecting D4 correctly, while keeping pin 10 as an output. I keep getting initialization failed! My setup is on the ICSP 6 pin configuration:
5V --> 5V
MISO --> DO
SCK -->CLK
GND --> GND
MOSI --> DI
D4 --> CS
RST is left out
Could you please tell me if the below ICSP is correct and whether the labels are correct for each pin. The ICSP2 diagram shows SPI outs for an Arduino, but the text below states that this is ICSP1. Could you please tell me the correct setup if image is incorrect?

OR here: https://www.dfrobot.com/wiki/index.php/ ... 9_ICSP.png
Here is my code:
#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
// pinMode(4, OUTPUT);
pinMode(10, OUTPUT);
// digitalWrite(4, HIGH); // Add this line
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}
5V --> 5V
MISO --> DO
SCK -->CLK
GND --> GND
MOSI --> DI
D4 --> CS
RST is left out
Could you please tell me if the below ICSP is correct and whether the labels are correct for each pin. The ICSP2 diagram shows SPI outs for an Arduino, but the text below states that this is ICSP1. Could you please tell me the correct setup if image is incorrect?

OR here: https://www.dfrobot.com/wiki/index.php/ ... 9_ICSP.png
Here is my code:
#include <SPI.h>
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
// pinMode(4, OUTPUT);
pinMode(10, OUTPUT);
// digitalWrite(4, HIGH); // Add this line
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop()
{
// nothing happens after setup
}
2018-09-25 23:24:46 Hi.
Accroding to you description of Beetle BLE and Adafruit MicroSD, I will given you link about Beetle BLE schematic files so you viwe the specific pins of ICSP1 and ICSP12.You canprogrammatically use D4 instead of D10.The SPI interface corresponds to ICPS1.
Hope help you.
https://raw.githubusercontent.com/Ardui ... 20V1.0.pdf
makermuyi
Accroding to you description of Beetle BLE and Adafruit MicroSD, I will given you link about Beetle BLE schematic files so you viwe the specific pins of ICSP1 and ICSP12.You canprogrammatically use D4 instead of D10.The SPI interface corresponds to ICPS1.
Hope help you.
https://raw.githubusercontent.com/Ardui ... 20V1.0.pdf
