Yet another ARM update (SD card version)

It has been a while since I have posted last on my process towards getting my AVC robot up and running. Part of that was getting busy around the house and at work. Part of the delay was not wanting to stop to post as I was making large strides. Tonight I am taking a short break.

Over the last week I have been crunching away writing device drives and getting the RTOS up and running. After that I started to work on the ability to write to an SD card for logging purposes. I purchased the AdaFruit MicroSd breakout board and started to convert over the ChanN FatFs file system. There was a port for my Atmel Sam7, but it was rather limited and used an old version of the code. So I started with the old sample, the new libraries, and as many web references as I could. As normal, much of the data was contradictory.

So I spent numerous frustrating evenings getting the basics working. For those few days, just getting a single command to reply properly would have been nice. Most of this time I had been debugging using print statements, GDB, and a logic analyzer. At some point what I was seeing on the LA make little sense. On the clock edge I was supposed to be sampling the SD card’s data (MISO), there was a glitch that sometimes would read as a zero and cause code to abandon with a fault. The glitch on the LA was just a few nano seconds wide right on the @#$# clock edge! How could that be? So I figured I had the wrong SPI phase or polarity. After many dead ends, I found a trusted source that clearly told me I had the right phasing. So where was the glitch coming from?

At some point sanity prevailed and I looked at the glitch using an oscilloscope. Here I discovered that by nano second glitch was actually the SD card tri-stating MISO for what ever idiotic reason. Without a pullup, the signal decayed for that single clock cycle and would occasionally  drop bellow the logic low threshold. I enabled the built in pull up on the micro, and suddenly things started to work. Two days later I was able to initialize, read, and write single sectors. I am still working of the FAT32 code, but that should come fast.

What did I learn? I learned that the “SPI mode” of an SD card is not really SPI. It is SPI-ish, or vaguely SPI like. With enough weird hacks you can get an SPI peripheral to talk to an SD card. But if I were doing this over again, I would have looked for a micro with an SD/MMC card peripheral interface.

 

This entry was posted in Arduino, AVC. Bookmark the permalink.