SdFs
SdFs copied to clipboard
SdBaseFile.createContiguous returning false
Hi, i have been writing to the SD card using a SdFatEX instance and SdBaseFile.
It was working fine however i'm now being returned false from the SdBaseFile.createContiguous() function.
The SD card has a 2MB file on it containing binary information, i can read the SD card using my computers SD card reader, but the Arduino cannot write to it?
I have debugged the error and the trace is:
FatFile.cpp: line 149: (count = 59, m_firstcluster= 0, startcluster = 0)
FatFileLFN.cpp: line 584: (m_vol->cache_sync() returns false.)
Here is my sample code:
inFileName = "test.bin" inFileLength = 480000
if (m_SD.exists(inFileName))
{
m_SD.remove(inFileName);
}
m_fileForStream.close();
// setup continguous file
bool contigFileOK = m_fileForStream.createContiguous(inFileName, inFileLength);
if (!contigFileOK)
{
// Error here <---------
}
// get the block range
bool rangeOK = m_fileForStream.contiguousRange(&m_blockBegin, &m_blockEnd); // 16000bytes file
if (!rangeOK)
{
}
// Flash erase all data in the file.
Serial3.println(F("Erasing all data"));
Serial3.flush();
uint32_t bgnErase = m_blockBegin;
uint32_t endErase;
while (bgnErase < m_blockEnd)
{
endErase = bgnErase + ERASE_SIZE;
if (endErase > m_blockEnd)
{
endErase = m_blockEnd;
}
if (!m_SD.card()->erase(bgnErase, endErase))
{
Serial3.println("erase failed");
Serial3.flush();
}
bgnErase = endErase + 1;
}
Serial3.println("Erase complete");
Serial3.flush();
// start the multiple block writing routine.
bool writeStartOk = m_SD.card()->writeStart(m_blockBegin, inFileLength / 512U);
if (!writeStartOk)
{
// print error
}
Write function called multiple times:
m_SD.card()->writeData(buffer of 512 bytes);
Stop function
bool stopWriting = m_SD.card()->writeStop();
if (!stopWriting)
{
// print error
}
m_fileForStream.close();
Maybe it has something to do with the sd format but i'm not sure, any help?
Thanks!
I resolved this issue, it was because i wasn't setting up the SPI interface after restarting the SD adapter.