Using of SdFat

Powersoft

Member
I use the code below for acces sd card on a esp32.
The goal is to read blocks. This is my routine to read a Forth screen into the memory.
This is part of my 6502 emulator running with the teensy 4.1.
.
Is this possible, and what to change to get it running on my teensy.
Thanks for any help.

Cheers,
Jan



C++:
#include "SdFat.h"

SdFat32 sd; // for FAT16/FAT32
File32 file;
File32 file_RW;



void RW(byte *codebuffer, int adr, int blk, int f)
{
  int bytes_per_block = 128;
  if (f==1) /* read from disk to memory */
  {
    file_RW.seekSet(blk*bytes_per_block);
    for (int i=0; i<bytes_per_block; i++) codebuffer[adr+i] = file_RW.read() & 0x7f;
  }
  else /* write from disk to memory */
  {
    file_RW.seekSet(blk*bytes_per_block);
    for (int i=0; i<bytes_per_block; i++) file_RW.write(codebuffer[adr+i]);
  }
}


void setup()
{
  Serial.begin(115200);
  SPI.begin(14, 2, 15, 13); //SCK, MISO, MOSI,SS
  Wire.begin();
  if (!sd.begin(13,SD_CONFIG))
 
  {
    Serial.println("sd.begin failed!");
    return;
  }
  else Serial.println("sd active");
}
 
Looks like it ought to work if you delete the unnecessary SPI.begin() and Wire.begin(), and if your SD_CONFIG is defined properly (not shown in the code fragment).
 
Looks like it ought to work if you delete the unnecessary SPI.begin() and Wire.begin(), and if your SD_CONFIG is defined properly (not shown in the code fragment).
Wich
Looks like it ought to work if you delete the unnecessary SPI.begin() and Wire.begin(), and if your SD_CONFIG is defined properly (not shown in the code fragment).
Thanks, shouls I install a special SDFat library to get it running?
 
I have no clou how to atach the sd card. Use this code but sd card is not mounted.

Code:
SdFat32 sd; // for FAT16/FAT32
File32 file;
File32 file_RW;


#define SD_CONFIG  SdioConfig(FIFO_SDIO)
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(16))

void setup() {
  Serial.begin(230400);
  // Initialize the SD.
  if (!sd.begin(SD_CONFIG))
    Serial.println("Error mounting sdcard");
  else
   Serial.println("Error mounting sdcard");

}

void loop() {
  // put your main code here, to run repeatedly:

}
 
You are printing an error message even if sd.begin() succeeds, so maybe it is actually working

Code:
  if (!sd.begin(SD_CONFIG))
    Serial.println("Error mounting sdcard");
  else
   Serial.println("Error mounting sdcard");  // <---- this should be something like "sdcard mounted OK"
 
Back
Top