As I mentioned in my previous post, I tossed in a SD card port for the TinySensor v1.1. I wanted to give it a live test and see if/how it works prior to submitting the PCB to the fab house. So I did a breadboard setup as per TinySensor v1.1’s schematic (MCU+SD part only). Next, I decided that I want to do this in the Arduino IDE because it is much more accessible to the general public than AVR-GCC stuff. I hope that one day to sell the TinySensors in the store, so this is a step in preparing for that moment. So, for Attiny processors the logical step was to use the Petit FAT FS library that I also used in the SD card bootloader project:
Petit FatFs is a sub-set of FatFs module for tiny 8-bit microcontrollers. It is written in compliance with ANSI C and completely separated from the disk I/O layer. It can be incorporated into the tiny microcontrollers with a small memory even if the RAM size is less than sector size.
- Very small RAM consumption (44 bytes work area + certain stack).
- Very small code size (2K-4K bytes).
- Supports FAT32.
- Single volume and Single file.
- File write function with some restrictions.
As I mentioned earlier, I wanted to use the Arduino IDE and so Google revealed an Arduino wrapper for the library that was exactly what I needed.
I modded the spi_init, rx and tx functions accordingly as per the ATTiny84 datasheet and loaded some test code that would read a file “test.txt” from the SD card and output it contents to a serial output via an FTDI cable (Attiny84 supports virtual serial).
It didn’t work. I tried over several times, check and double-checked my wiring but to no joy. The I researched on the subject and came across this forum discussion that explained the cause of my troubles: The SD card pins labeled MISO and MOSI don’t go to ATTiny84’s pins labeled MISO and MOSI.. they need to be swapped. Basically this outlines it:
The MOSI and MISO signals are for ISP mode only. Sharing the same pins are DO and DI which can be used by the USI. When working with the USI, pretend MOSI and MISO do not exist. DO is always the output, DI is always the input.
So I swapped the wires on the breadboard and it was working 🙂
That of course called for changing the TinySensor plans accordingly, the PCB designs are now updated to v1.2.
Here are some pictures
The Petit FAT FS library port for Arduino with the examples I used are available on github
Page views: 12104