ITead

The SDuFAT library has some basic function for file log, can not meet some more complex requirements. Now Henning Karlsen publish a TinyFAT library and it's really more powerful than former. And it had been designed to integrate with ITDB02_Graph and ITDB02_Graph16 - so now you can easy to use this library to read out the image in the SD cards and display on ITBD02 LCD module.

The library supports FAT16 formatted SD cards up to 2GB in size. 4GB FAT16 formatted SD cards might work, but is untested. Long filenames are not supported. Keep you filenames compliant with the old 8.3 standard.

file.buffer[];Buffer used for reading and writing SD-card sectors.Variables:file.buffer[0-511]: Byte-array to hold one sector of data.

file.MBR;Master Boot Record of the SD card.Variables:Part1Type: Partition1 Type. Only types 0×04, 0×06 and 0×86 can be used.part1Start: First sector of Partition1.part1Size: Number of sectors in Partition1.

file.BS;Boot Sector of Partition1.Variables:

sectorsPerCluster: Number of sectors per cluster.reservedSectors: Number of reserved sectors.fatCopies: Number of File Allocation Tables in partition. Almost always 2.rootDirectoryEntries: Maximum number of root directory entries.totalFilesystemSectors: Total number of sectors available to the file system.sectorsPerFAT: Sectors per File Allocation Table.hiddenSectors: Number of hidden sectors preceding the partition that contains this FAT volume.partitionSerialNum: Partition serial number.fat1Start: First sector of primary File Allocation Table.fat2Start : First sector of secondary File Allocation Table.partitionSize: Size of partition in MB.

file.DE;Directory Entry structure. Used by findFirstFile() and findNextFile().Variables:

vanduino

I am using an ITDB02S with a Mega2560. I can make it work with Henning Karlsen's libraries. Graphics and touchscreen are fine. I can access the SD card with the tinyFAT library, but only if I use the default SPI select ( pin 53 on the Mega). However, I have multiple SPI devices and I need to use a different select pin. The tinyFAT setSSpin() function is not helpful. Is there a way to do this?

It should have read file.setSSpin(); when i want to change SD SS to pin 8 it hangs, i dont know if its the SD or duemilanove thats hanging, SD & ethernet work seperatly with SS on pin 10 but not together even if i set SS to 8 or 9, Im starting to get anoyed with it now

vanduino

For the SPI to work, pin 10 (Uno, etc), or pin 53 (Mega), must be set to output, whatever pin you eventually assign to SS. If this is done, you should be able to use pins 8 or 9, as long as they are also set as outputs. As for using other pins as SS, or debugging, keep reading.

TinyFAT uses an auxiliary file called mmc.cpp. This is where the SS initialization and SPI handshaking occur. For my Mega application, I found that it was reassigning the SS pin, but not correctly setting the DDR register associated with the new pin's port. This is not very complicated. Each physical I/O pin on the Arduino belongs to a port (PORTA,PORTB,PORTC,...) and each port has a data direction register associated with it (DDRA, DDRB, ...).

mmc.cpp does its SPI protocol stuff by port manipulation. It needs to know 3 things at initialization: The SS pin, the PORT associated with the SS pin, the DDR for that port. For the most Arduinos except the Mega, this defaults to pin 10, PORTB, DDRB. Pins 8 and 9 should also be PORTB and DDRB. For the Mega, the default SS is pin 53, PORTB, DDRB. Other pins may have other ports and DDR's. But you can use any other pin available if you just make sure mmc.cpp is using the correct 3 parameters for its calls. I was able to do this for the Mega by cleaning up mmc.cpp.

Here are the relevant parts of mmc.cpp that I changed. I have set it to use pin 42 as the default SS for the Mega, but it can be set to any pin.

counter = 0xffff; // According to the spec READ_OCR should work at this point // without retries. One of my Sandisk-cards thinks otherwise. do { // Send CMD58: READ_OCR i = sendCommand(READ_OCR, 0, 0); if (i > 1) { // kills my Sandisk 1G which requires the retries in the first place // deselectCard(); } } while (i > 1 && counter-- > 0);

if (counter > 0) { answer = spiTransferLong(0);

// See if the card likes our supply voltage if (!(answer & SD_SUPPLY_VOLTAGE)) { // The code isn't set up to completely ignore the card, // but at least report it as nonworking deselectCard(); return STA_NOINIT | STA_NODISK; } }

vanduino

In the above posted code, in the method mmc::setSSpin(pin), I am only allowing the Mega SS pin to range through PORTL (pins 42-49) and the Uno SS pin to range through PORTB pins 8-10. To use other pins outside this range for SS, just expand the conditional to assign SSPORT and SSDDR to the proper values for the pins you might want to use. You will need to look at an Arduino pin map. I reserved PORTL for SS choices for my Mega application. That gave me 8 more SS pins, so potentially 8 more SPI devices beyond the default device. So I didn't bother to code for more options.

Sorry if this sounds like a dumb question, but I'm new to this library and to writing to SD cards in general.

It appears that using file.writeLn(text); does ONLY that ... writes text to a file. I am wanting to log data from a magnetometer and need to create a data string to be written in CSV format. As an example, I want to execute something like this...

But the library won't allow anything except text between quotes. This to me seems to be pretty useless if I cannot pass anything but ASCII text to the function. Is there a method to create a char array containing my data and the comma seporator, and append each character to the same line, and then a CR / LF at the end of the array? This is so frustrating because I spent a great deal of time getting SPI to work with my shield and SD card. The datalogging is the only obstacle in the way of completing this project !!!

I must have struck a nerve with someone. I meant no disrespect...just that I was trying to figure out how to use tinyFat to write data not text to a file. I know the arduino is a C environment, but if you look on the official arduino page they call it a 'wiring' language.

How are friends ..... I could help with a problem that I have ..... the problem is that I use the library and tinyFAT uTouch Mega2560 library with Arduino and a screen 3.2 "LCD TF Card Shiel REV.B to time to load the progam works well only me and the library tinyFAT uTouch not work and so I myself uTouch works and does not work tinyFAT me the problem is that these libraries use the same MOSI, MISO and SCK and when activate either touch or pin for pin sd works just me one and not to see the two in the same program and I hope I can help I will be very grateful in advance ............ ...

It happens the same as Esllerena, combining tinyFAT library and uTouch the pictures are displayed correctly stops working but the touch part must be that both the touch part to the SDcard used the same pins MOSI, MISO and SCK , note that I'm using ARDUINO MEGA board. (separate libraries work properly)

Please show your support and fix this, or another way to handle images in raw format and can be used uTouch .. thanks for your help

- See more at: http://blog.lincomatic.com/?p=1074#sthash.rqzXOtS8.dpuf