Okay, I've changed the program to get more information about what is going on with my SD connection. It's copied from here http://mb-raw.blogspot.com/2017/07/t...l-sd-card.html
Code:
#include <SD.h>
#include <SPI.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 10;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
SD.begin(chipSelect);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
if (volumesize < 8388608ul) {
Serial.print("Volume size (bytes): ");
Serial.println(volumesize * 512); // SD card blocks are always 512 bytes
}
Serial.print("Volume size (Kbytes): ");
volumesize /= 2;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
Firstly, I decided to use the basic version, without any changes in pinout of SPI. As a result in the Serial I got this:
Code:
Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card
It made me think, that I got a problem with my card, I should format it properly, so I made it with this formatter (https://www.sdcard.org/downloads/formatter/), it changed nothing.
But then the courier came, I got a package with Teensy 4.0, so I instantly soldered pins to it and connected it to the whole circuit - bingo!, the basic SPI (using CS - 10, MOSI - 11, MISO - 12, SCK - 13) worked well! Notice, that I didn't change the circuit, didn't format SD card, change the code, etc. I got this message in serial:
Code:
Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 3952607232
Volume size (Kbytes): 3859968
Volume size (Mbytes): 3769
Files found on the card (name, date and size in bytes):
SYSTEM~1/ 2021-06-24 11:39:14
WPSETT~1.DAT 2021-06-24 11:39:14 12
INDEXE~1 2021-06-24 11:39:14 76
TEST.TXT 2000-01-01 01:00:00 448
DROPBO~1.DEV 2021-06-24 11:40:16 56
1504TO~1.TXT 2020-08-06 15:27:30 213
I decided to go level up - I soldered SCK to the pin 27 (SCK1) - to avoid the collision with FreqCount library - first fail - It didn't work. I thought, maybe I cannot mix SCK1 pins with SCK - soldered also pin 26 as MOSI, and connected CS as pin 0, and MISO as 1 - still, in the serial message about wrong connection. Then I found out interesting thing - I can declare anything in a line SPI.setSCK(x) - if I put 50 or 35 as 'x' Teensy ignore it, it think, that SCK is still declared as 13. Here is a screenshot: