Show Posts
Pages: 1 ... 61 62 [63] 64 65 ... 99
931  Using Arduino / Storage / Re: SD.open hanging device? on: June 18, 2012, 11:30:49 am
Remove this stuff:
Code:
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

It duplicates stuff already in SD.h.
932  Using Arduino / Storage / Re: Will SD card write speed improve performance? on: June 18, 2012, 11:18:59 am
The SD card class/speed has little to do with write speed.  The speed class is based on very large sequential writes using the SD write multiple command with pre-erase and the 4-bit SDIO bus.

The Arduino uses the SD single block write command with the SPI bus.  Often very cheap class 2 cards have better write speed on Arduino than class 10 cards.

You need to benchmark the card to see what its performance will be on Arduino.  You can use the SdFat bench example.

SdFat is the base library for SD.h and is here http://code.google.com/p/sdfatlib/downloads/list.
933  Using Arduino / Storage / Re: file read times depending on directory file count? on: June 16, 2012, 01:42:21 pm
You need to rewind the directory file.

Code:
  sd.vwd()->rewind();
934  Using Arduino / Storage / Re: arduino uno r3 and sparkfun microSD Shield (vol.init failed SD errorCode: 0X4 ) on: June 16, 2012, 01:39:31 pm
If you have tried two SD cards and they both fail with Sparkfun examples you should contact Sparkfun.  It is likely a problem with the Sparkfun shield.

Once again your errors are not due to the card format.  They are basic communication failures with the SD card.

You should not format cards of 2 GB or less with FAT32 filesystems.  FAT16 is more efficient on smaller cards.

The SD formatter here https://www.sdcard.org/downloads/formatter_3/ will produce the optimal format for your card.  This program is provided by the SD association and complies with the SD format standard.
935  Using Arduino / Storage / Re: SD card access using variable as filename, file not found on: June 15, 2012, 01:37:37 pm
You declare a nine byte array but initialize ten bytes.  Star needs to be eleven bytes long and add the null byte as suggested by countrypaul.

Change to:
Code:
  char Star[11];

Add:
Code:
  Star[10] = 0;

936  Using Arduino / Storage / Re: How long time does is take to write to an SD? on: June 14, 2012, 05:10:14 pm
The bench example writes 100 bytes at a time.  The bench example writes a five MB file so 50,000 write calls are executed.

The maximum latency is the maximum time to execute this statement:
Code:
  file.write(buf, sizeof(buf))
Where buf is a 100 byte array.

A latency of over 300 ms is unusually long.  150-200 ms is more common. 

The maximum latency generally occurs when a SD card erases a large number of blocks of flash memory.  It can also be related to wear leveling or remapping a bad spot.
937  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.
938  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.
939  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.
940  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
941  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);
942  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.
943  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
944  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
945  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.
Pages: 1 ... 61 62 [63] 64 65 ... 99