Getting SD errorCode: 0X30,0XFF when trying to open SdBaseFile configFile.open("config.txt", O_READ)
Using SdFat library. Tried versions 1.0.3 and the later 1.1.2 with the same results.
It was working fine for a couple of days and then suddenly quit with the above error happening rather consistently. I'm using TXB0104 for level shifting.
Can anyone shed some light on what the error code means?
How can I debug further?
With no microSD inserted, sd.begin(SD_CS_PIN, SPI_FULL_SPEED) never returns.
I've soldered the ATmega328P-MMH to a breakout board and wired all the connections.
It is my sketch. However, it had been working for some time and then suddenly broke.
I have tried couple of other cards and they work in a similar ATmega328P-AU based system.
I did see where it fails trying the CMD17. However, I don't know what might be possibly wrong when CMD17 fails. One obvious reason could be bad SD card but I have ruled out that possibility. I've visually inspected all the connections and checked for continuity but it all looks good.
My system is part of a larger system connected to an ESP and communicates with ESP via MinimumSerial. There is no appropriate example that will fit the scenario unless I'm missing something (please point to an example in that case).
I have a similar system that has actually worked for years that is using 74HC4050 as voltage level shifters. I have now designed a new system that uses bi-directional voltage level shifters using TXB0104. It worked nicely for couple of days when one day it suddenly stopped reading files on the microSD (if inserted) or won't even return from call to SD.begin(CS_PIN) if no card is inserted.
I'm able to upload new sketches using 'Arduino as ISP' using the same lines as microSD except only one device is connected at a time. The sketch is supposed to read data from the microSD and return it back to ESP over SoftwareSerial based on reading a command from ESP.
It's a fairly complex system (at least to me) and I didn't want to go through replacing each component or rewiring everything (I just did that once because of some other issue).
I was hoping to be able to debug more such that I'm able to narrow down what might be the issue so that I can start there.
Thanks for keeping up with me.
P.S. - I'm able to swap cards and tried a few that work in the old system without issues.
Yes. All cards fail in the new system but work in the old system.
Yes. I could. However, I'm unable to isolate my module to run those sketches.
However, I've managed to find the problem. Sometimes, the problem exists where you least expect. After re-soldering all the connections, rechecking for continuity and scoping the signals, I was totally thrown off to realize that SD card was getting the correct signals but still unable to read it. I tried to add a beefier 3.3V supply but no luck. I had tried to even load the exact same sketch that works on older system but it will not work.
Finally, I loaded the exact compiled hex code that is present on the older system and it worked! So, it had to be my code. But all I added was couple of debug statements to see why it wasn't working. After much investigation, it turned out to be a mix of two problems.
When things stopped working in the beginning, it seems that for some reason Arduino 1.6.5 that I have wasn't building properly. It had to be quit and restarted for the build to produce the correct output.
To debug that, I had added a debug statement like:
MinimumSerial ms;
...
ms.print("ABC"); //this is where the problem is
configFile.open("config.txt", O_READ);
As strange as it may seem, it turns out that trying to open a file after printing a STRING with MinimumSerial doesn't work. Note that if I print a single character at a time, it all works but a double quoted string is an issue. I've verified it over and over.
I would be delighted to know why that is happening.
If adding (or removing) Serial prints / writes makes your application misbehave, it's often an indication of a memory issue.
You mention String (capital S); incorrect use of String objects can cause this type of problem. I haven't seen your full code, but e.g. passing a String object as a parameter to a function places a copy of the String object on the stack. It will be better to use a reference to the String object.
Check boundaries of arrays; any writing outside the the array can cause this type of problems.
Possibly saving a few bytes of RAM when using ms.print(F("ABC")).
No, the terminating nul character is not printed. I was referring to any array in your code, not (necessary) the array of characters that you show here.
That's not a lot. Is all your fixed text in PROGMEM?
You can check the actual usage by moving local variables to global space and check how memory usage develops. It's probably a lot of work and you might have to rename variables )if variable names are the same in multiple functions.
OK. That part is fixed. It saved me 8 more bytes which is probably not bad (about 4% ?).
That is something I had done much earlier but I can look again.
Now, onto more interesting stuff. Just when I thought it was all working, it seems that I tend to receive serial data in my ESP as chunks of 4 bytes! So, if I was sending "ABCDE" instead of earlier "ABC", on using the SoftwareSerial.readBytes API of my ESP, I get the data in two read calls as "ABCD" and "E".
That is to be expected. It could also be 2 bytes followed by 3 bytes or 1 byte plus 2 bytes plus 2 bytes. Never expect a serial message to arrive in one chunk.
Thank you once again. I modified my code to read byte by byte with a delay in between. It turned out that in the process I uncovered a bug in my code that was reading the bytes. I've fixed it and things look working again.
Thanks again. I'll post more if I run across any issue again.
Great thread! Thank you for pointing me to that. Definitely a lot to learn from it.
In my case, I'm reading serial data in both setup() as well as loop(). Reading within the loop(), in fact, I'm doing exactly what the thread says. setup() is where I've added some new code and I had to use delay() to make it work. However, I've reverted to readBytes() after I fixed the bug that was trying to read an incorrect number of bytes.