Show Posts
Pages: 1 ... 70 71 [72] 73 74 ... 107
1066  Using Arduino / Storage / Re: file read times depending on directory file count? on: June 13, 2012, 08:11:09 pm
You don't want fat16lib which is a smaller FAT16 only library.  I also wrote SdFat which is the base for the official Arduino SD.h library.  SD.h uses a very old version of SdFat.  SdFat supports FAT32 and FAT16.

openNext() does not cycle but you simply rewind the directory to restart.  Directories are just files so you can position them with rewind or seek.
1067  Using Arduino / Storage / Re: file read times depending on directory file count? on: June 13, 2012, 07:14:13 pm
You need to use SdFat.  The SD.h library is a wrapper for an old version of SdFat.  SD.h presents a slightly modified API for SdFat but adds no features.

SdFat is here http://code.google.com/p/sdfatlib/downloads/list or beta versions are here http://code.google.com/p/beta-lib/downloads/list.

In addition to open by index, you might be able to use openNext().  OpenNext() should be a fast way to open every file in sequence.
1068  Using Arduino / Storage / Re: arduino uno r3 and sparkfun microSD Shield (vol.init failed SD errorCode: 0X4 ) on: June 13, 2012, 02:41:42 pm
These errors are basic hardware errors and are not related to the SD card's format.  They are errors reading the card's CID and CSD registers.  This has nothing to do with data on the card or the card's format.

Can you try another SD?  The SD is accessed in SPI mode on Arduino so the fact that you can access the card form a PC or Mac does not prove the card works in SPI mode.
1069  Using Arduino / Storage / Re: How long time does is take to write to an SD? on: June 13, 2012, 02:33:38 pm
The time to do a write depends on the card and the state of the card.  The SD spec allow a card to take as long as 200 ms.

Run the SdFat bench example.  it will print the max latency.  Here is output for a typical card with a max latency of 156 ms:
Quote
Type any character to start
Free RAM: 1035
Type is FAT16
File size 5MB
Starting write test.  Please wait up to a minute
Write 192.83 KB/sec
Maximum latency: 155956 usec, Avg Latency: 513 usec

Starting read test.  Please wait up to a minute
Read 295.49 KB/sec
Maximum latency: 2808 usec, Avg Latency: 333 usec

Done
1070  Using Arduino / Storage / Re: file read times depending on directory file count? on: June 13, 2012, 02:25:14 pm
Opening a file requires a search of the directory file.  Each directory entry is 32 byte long with a 11 byte file name.  Reading the entry and doing a compare of the name in the directory with the name of the file to be opened takes time.

Directory entries are not in any simple order. When a file is created the first free entry is used.  This means a sequential search must be used.

If you started with a freshly formatted SD and created the files in the order you want to access them you could use the SdFat function to open the file by index.  This function is very fast but tricky to use.

Here is the function with doxygen documentation comments:
Code:
//------------------------------------------------------------------------------
/** Open a file by index.
 *
 * \param[in] dirFile An open SdFat instance for the directory.
 *
 * \param[in] index The \a index of the directory entry for the file to be
 * opened.  The value for \a index is (directory file position)/32.
 *
 * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
 * OR of flags O_READ, O_WRITE, O_TRUNC, and O_SYNC.
 *
 * See open() by path for definition of flags.
 * \return true for success or false for failure.
 */
bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag);
1071  Using Arduino / Storage / Re: SK Pang dmx / sd shield + mega2560 on: June 08, 2012, 01:07:04 pm
Hardware SPI will be faster but open time depends a great deal on where the file to be opened is located in the directory.

Hardware SPI is 4 MHz and software SPI is about 1 MHz for SD.h but you will probably get only a factor of two speed-up at most for read/write and even less for open().

You will see almost no improvement if you write to an SD using print.  All the overhead is in formatting numbers, not in transferring data over the SPI bus.
1072  Using Arduino / Storage / Re: SK Pang dmx / sd shield + mega2560 on: June 08, 2012, 11:23:11 am
The Ethernet shield connects to the SPI bus through the ICSP connector so it will work with a Mega.

The Arduino DMX Shield appears to use pins 10 - 13.  These are not SPI pins on the Mega.

It may be possible to use software SPI on the Mega.

Edit the Sd2Card.h file in the libraries/SD/utility folder.  At about line 42 set MEGA_SOFT_SPI to one like this.
Code:
#define MEGA_SOFT_SPI 1
1073  Using Arduino / Storage / Re: How to use SD library over SPI for logging SPI sensors? on: June 08, 2012, 09:01:57 am
You don't need to do anything with SdFat if you downloaded sdfatlib20111205.zip from http://code.google.com/p/sdfatlib/downloads/list.

SdFat handles setting the correct SPI mode internally with this code for selecting the SD:
Code:
/**
 * Initialize hardware SPI
 * Set SCK rate to F_CPU/pow(2, 1 + spiRate) for spiRate [0,6]
 */
static void spiInit(uint8_t spiRate) {
  // See avr processor documentation
  SPCR = (1 << SPE) | (1 << MSTR) | (spiRate >> 1);
  SPSR = spiRate & 1 || spiRate == 6 ? 0 : 1 << SPI2X;
}
void Sd2Card::chipSelectLow() {
#ifndef SOFTWARE_SPI
  spiInit(spiRate_);
#endif  // SOFTWARE_SPI
  digitalWrite(chipSelectPin_, LOW);
}
 

The only option is the SPI speed which is set in the init call
Code:
 if (!sd.init(SPI_HALF_SPEED, CHIP_SELECT)) sd.initErrorHalt();

You need to provide similar code for your sensor to set the correct SPI mode/speed when you access it.

Set the SPI mode for your device after these lines:
Code:
void writeRegister(int pin, char registerAddress, char value){
  //Set Chip Select pin low to signal the beginning of an SPI packet.
  digitalWrite(pin, LOW);

Edit:
Have you verified that the SD is wired correctly by running a program like the SdFat QuickStart example?

To try QuickStart insert code at the begining of setup() to set chip select for your device high like this:
Code:
void setup() {
  pinMode(YOUR_DEVICE_CS_PIN, OUTPUT);
  digitalWrite(YOUR_DEVICE_CS_PIN, HIGH);
  // rest of QuickStart setup code here
1074  Using Arduino / Storage / Re: How to use SD library over SPI for logging SPI sensors? on: June 07, 2012, 05:39:40 pm
The Arduino SPI library doesn't work well for sharing the SPI bus among/between devices.

The old version of SdFat used as the base SD.h also doesn't share the SPI bus well.

The problem is that all SPI options must be set each time you access an SPI device.

I am the author of SdFat and have modified newer versions of SdFat to set all SPI options each time SD chip select is made low.

The SPI library should be modified to take into account the fact that each SPI device require its SPI options to be set before transfering data.
1075  Using Arduino / Storage / SDXC and SdFat on: June 07, 2012, 12:21:21 pm
Any interest in using SDXC cards with SdFat? 

SDXC cards have a capacity from 64 GB to 2 TB.  Currently 64GB and 128GB cards are available.

SDXC cards are normally formatted with an exFAT file system but I was able to format a 64 GB SDXC card as FAT32 and use it with a modified version of SdFat.

I used this card http://www.amazon.com/Komputerbay-Speed-Class-Memory-Write/dp/B005793ZTW/ref=sr_1_11?s=electronics&ie=UTF8&qid=1339086813&sr=1-11

The card seems to be accepted by Windows 7 with the FAT32 format.  Windows 7 will only format the card exFAT or NTFS.

The FAT32 formatted card also seems to work with the preview version of Windows 8.

FAT32 formatted SDXC cards work on Linux and Macs and these systems will format an SDXC card as FAT32.

If there is interest, I will post a beta of SdFat that can read, write, and format SDXC cards FAT32.

The current version of SdFat has several problems with SDXC cards and the SdFormatter sketch will not correctly format SDXC cards as FAT32.

FAT32 limits individual files to a max size of 4 GB.  The SDXC standard exFAT format has no file size limit.

exFAT is a proprietary Microsoft file system.  I am following efforts to produce a stable open source exFAT implementation.
1076  Using Arduino / Storage / Re: Sdfatlib readData and readStart failing on: June 06, 2012, 08:15:15 am
The problem is myfile is not the object that can access the SD card.

You need to use sd.card() like this:
Code:
#include <SdFat.h>
SdFat sd;
SdFile file;
const int chipSelect = 10;
uint32_t bgnBlock;
uint32_t endBlock;
uint8_t bufferOne[512];
void setup() {
  Serial.begin(9600);
  if (!sd.init(SPI_FULL_SPEED, chipSelect)) sd.initErrorHalt();
  file.open("axelf.snd",O_READ);
  Serial.println(file.contiguousRange(&bgnBlock, &endBlock));
  Sd2Card *card = sd.card();
  Serial.println(card->readStart(bgnBlock));
  Serial.println(card->readData(bufferOne));
  for (uint8_t i = 0; i < 20; i++) {
  //  Serial.println(bufferOne[i], HEX);
  }
}
void loop() {}
1077  Using Arduino / Storage / Re: 1 GB microSD on MAC on: June 05, 2012, 12:39:18 pm
It might work but this is a poor solution.  Resistor based level shifters fail with many newer SD cards since new cards have edge detectors for the signals and resistors round signal edges.

This is the reason that almost all commercial products now use semiconductor buffers/level shifters.

Good luck if you try it.  You might want to download the new SdFat beta and enable CRC to detect any data errors and slow down the SPI clock.

The SdFat beta with CRC is SdFatBeta20120327.zip http://code.google.com/p/beta-lib/downloads/list
1078  Development / Other Software Development / Re: ChibiOS/RT 2.4.1 RTOS update on: June 04, 2012, 04:31:31 pm
I don't think ChibiOS is the best choice but you can arrange for cooperative multitasking.

Quote
#define CH_TIME_QUANTUM   20

Round robin interval.

This constant is the number of system ticks allowed for the threads before preemption occurs. Setting this value to zero disables the preemption for threads with equal priority and the round robin becomes cooperative. Note that higher priority threads can still preempt, the kernel is always preemptive.

Note:
    Disabling the round robin preemption makes the kernel more compact and generally faster.

Definition at line 70 of file chconf.h.

Referenced by _scheduler_init(), chSchDoReschedule(), chSchGoSleepS(), and chSchWakeupS().
1079  Using Arduino / Storage / Re: What is the max microSD size for the eithernet shield? on: June 04, 2012, 04:14:42 pm
Yes they could be reformatted and I have an SDXC that I am playing with on Arduino.

The problem is that Microsoft can prevent reformatted SDXC cards from being used in their OSes and probably in Macs and many other devices that must license their exFat format. 

The SD association states that reformatted cards shall not be accepted by SD association members in products they produce.

I am looking at the Linux exFat driver but it is so incomplete.  Much of the exFat file system is still a mystery and the code has many gaps in file system declarations.

I expect there will be a good reverse engineered description of exFat and good open source code soon.
1080  Using Arduino / Storage / Re: 1 GB microSD on MAC on: June 04, 2012, 04:00:05 pm
Don't try any other micros SD cards.  They may be damaged by the high voltage signals.
As Sparkfun says about their shield:
Quote
All new microSD shields have a voltage converter chip on-board that converts the Arduino 5V signals to 3.3V signals in accordance with SD specifications. No more 'blown up' SD cards!

The best approach is to use a level shifter like these adapters/shields

http://www.adafruit.com/products/254

http://www.gravitech.us/micaad.html

http://www.sparkfun.com/products/9802

You could try resistor level shifters but these don't work well with many cards.  If you try this, slow down the SPI clock.
Pages: 1 ... 70 71 [72] 73 74 ... 107