Does SdFat support multiple open contiguous files?

Does SdFat support multiple open contiguous files?

I am using AnalogBinLogger example for reference, running on a Due, and adding another SdBaseFile variable and a modified createBinFile() function to initialize it produces this output (retained output from createBinFile())

Initializing SD card...ADC file

Creating new ADC file
Erasing all data

Creating new HMC file
error: createContiguous failed
SD errorCode: 0X30,0X0

The contiguous file support in SdFat is said to have been tough to add, and that it uses borderline minimum buffers to allow it’s use on modern cards, perhaps this is why it was limited to 1 such file open? I have not found examples using multiple contiguous files.

Of course, I can use the one file, but then adding another sensor as a data source would change the entire format.

What my program needs to do is log >120KB/s ADC (it does this fine) and also some SPI sensors to a bin file.

  1. Also more often than not, the already present tmp contiguous file on the card can’t be deleted, when I turn off/switch on serial monitor (reset Due). So I have to do it manually. The file is corrupt on Windows. This happens because,

  2. I can’t make SdFat work with SPI sensors used on the Due and I have tried everything. The code I use is tested to work without SdFat, with same wiring. Only using ADC from DMA works great, but I need SPI sensors too.

I have tried with, and without,

#define USE_SHARED_SPI 1

SdFatConfig.h USE_STANDARD_SPI redefined to 1 to avoid using DMA for SPI in SdFat

SPI speed setting from card init to maximum speed the SPI sensor supports (divider 12, should be 7MHz, sensor supports up to 8MHz).

also tried disabling ADC DMA…

added code to make sure to not use SPI from DRDY interrupt routine while SdFat is using SPI, like this

//4ms
void HMC_DRDY()
{
  interruptInProgress=1;
  digitalWrite(LED_BUILTIN, HIGH);
  //Serial.println("DRDY");
  //max 1ms
  
  if(sdInProgress==0)
  {
  sd.card()->spiStop();//max 0.1ms
  delay(1);
  //serialInProgress=1;
  //setup to 8MHz, or use 8MHz for everything
  //HMCcs=1;
  Magnetometer.read_all_mags();//max 0.1ms
  //HMCcs=0;
  //copy to HMC buffer
  Magnetometer.writeHMCbuffer();
  //setup to 20MHz
  sd.card()->spiStart();//max 0.1ms
  //serialInProgress=0;
  }
  digitalWrite(LED_BUILTIN, LOW);
}
if(bittrigger>0)
  {
  // if the file is available, write to it:
  if (binFile.isOpen()) {
    n=0;
    for(int i=1;i<1<<NBUFFER;i=i<<1)
    {
      if((bittrigger&i)>0)
      {
        while(interruptInProgress==1)
        {        }
        //detachInterrupt(HMC5983::HMC5983_DRDY_pin);
        sdInProgress=1;
        bittrigger=bittrigger&(~i);
        digitalWrite(LED_BUILTIN, HIGH);
        binFile.write((char*)(buf[n]),512);
        digitalWrite(LED_BUILTIN, LOW);
    
#ifdef SERIALOUTPUT
    Serial.print("B ");
    Serial.println(n);
#endif
        sdInProgress=0;
        //attachInterrupt(digitalPinToInterrupt(HMC5983::HMC5983_DRDY_pin), HMC_DRDY, FALLING);
      }
      n=n+1;
    }
  }
  // if the file isn't open, pop up an error:
  else {
    #ifdef SERIALOUTPUT
    Serial.println("error opening datalog.txt");
    #endif

  }
  }

So the question is, can anyone direct me to any working example of using SdFat with other SPI devices on the bus on the Arduino Due? The only available example of using SPI sensors while using SdFat on Arduiono Due is the one I used for reference on the sd.card()->spiStop(); sd.card()->spiStart(); block.

If it is impossible, I shall use SoftSPI, I2C… and probably doubled device.

I'm far from knowledgeable in thus area and i'm not sure if this applies to the Due.

I however have read that there are SD modules that don't release the output when SS is de-activated due to a design flaw around the kevel shifter (dies your module have a level shifter?). That will interfere with other traffic (e.g. from your sensors) when try to read from your sensors. Might that be happening in your setup?

I found the Catalex SD card breakout board sensor's interface chip is not wired to release the MISO line. I was able to overcome this with a mode to the card.

mini SD breakout boards with no interface module do not work either. You would need to tristate the MISO pin

This only matters if you are using two SPI devices on the same port.

There are a number of posts on this subject if you search for Catlex.

John