Show Posts
Pages: 1 2 [3] 4 5 ... 107
31  Using Arduino / Storage / Re: rewindDirectory doesn't? on: July 06, 2014, 08:18:54 am
You need to post the code that doesn't work.  We can't guess what you are doing.

 rewindDirectory() is a simple wrapper for the SdFat rewind function.

Here is rewindDirectory:
Code:
void File::rewindDirectory(void) { 
  if (isDirectory())
    _file->rewind();
}

Here is the SdFat rewind function:
Code:
  void rewind(void) {
    curPosition_ = curCluster_ = 0;
  }

These are very simple functions so we need more info about your code.
32  Using Arduino / Storage / Re: SdFat behaviour has changed - anyone know what is going on? on: July 06, 2014, 07:19:30 am
You reposition the root directory to just after the file you open with this statement.
Code:
myfile.open("PLAYLIST.TXT", O_CREAT|O_WRITE); // <<-- my mod

Add this after the above open statement so openNext will start at the beginning of the root directory.
Code:
  sd.vwd()->rewind();
33  Using Arduino / Storage / Re: Read_write Problem on a SD card on: July 04, 2014, 10:26:00 am
Don't use these objects for routine access to an SD card:
Code:
Sd2Card card;
SdVolume vol;
SdFile root;

They are useful to diagnose problems but just use the SD object like this example:
Code:
/* SD card read/write example. Derived from the official example by Bill Greiman */

#include <SD.h>

// Change to SD chip select.
const int8_t sdChipSelect = 4;

// Chip select for any other SPI device or -1 if no other SPI device.
const int8_t otherChipSelect = 10;

File myFile;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    // wait for serial port to connect. Needed for Leonardo only
  }
  // Disable any other SPI device.
  if (otherChipSelect >= 0) {
    pinMode(otherChipSelect, OUTPUT);
    digitalWrite(otherChipSelect, HIGH);
  }
  Serial.print("Initializing SD card...");

  if (!SD.begin(sdChipSelect)) {
    Serial.println("initialization failed!");
    while(1);
  }
  Serial.println("initialization done.");
  
  // open the file.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
     Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
   // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
// nothing happens after setup
}

Here is typical output from a Mega:
Quote
Initializing SD card...initialization done.
Writing to test.txt...done.
test.txt:
testing 1, 2, 3.
testing 1, 2, 3.
34  Using Arduino / Storage / Re: Ethernet shield SD card initialization failed on: July 04, 2014, 09:00:51 am
Most users should never use the SS symbol in their code.  There is no need to set SS as an output.  Libraries that use the SPI bus configure SS correctly unless the library has a bug.

You must not use SS as an input in your code.
Quote
In master mode, the SS pin must be held high to ensure master SPI operation if this pin is configured as an input pin. A low level will switch the SPI into slave mode and the hardware of the SPI will perform the following actions:

1. The master bit (MSTR) in the SPI Control Register (SPCR) is cleared and the SPI system becomes a slave. The direction of the pins will be switched according to Table 2-1.

2. The SPI Interrupt Flag (SPIF) in the SPI Status Register (SPSR) will be set. If the SPI interrupt and the global interrupts are enabled the interrupt routine will be executed.

Quote
I had in mind that setting the SS pin to OUTPUT was meant to indicate to the card that there were some devices that were using SPI,  does it still work when you set it up to HIGH?
The SD card is a slave and doesn't care or do anything with other devices.   SD libraries don't look at the previous state of SS.  The libraries just configure SS as an output and sets it high.

The key thing is to set chip select for all SPI devices to output mode and high before calling any library that uses the SPI bus.  Chip select for a device may be the SS pin but that is irrelevant.
35  Using Arduino / Storage / Re: Resetting Time recording on: July 04, 2014, 07:29:12 am
The problem may be that you connect the serial monitor.  connecting the Serial monitor resets the Arduino so the file will look like your example.

Replace this:
Code:
  Serial.println("card initialized.");

With this:
Code:
  Serial.println("card initialized.");
  File testFile = SD.open("tar.txt", FILE_WRITE);
  testFile.println("restart");
  testFile.close();

This will show when the reset happens.
36  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 29, 2014, 08:29:55 am
I would pay more for Nucleo since I like the form factor and STM32 chips.  See the attached photo of my test setup with an Adafruit Data Logging shield.  

The double rows of male pins bring out all chip signals and voltages, and are on both sides of the board.  The pins just match the low cost proto 7x9 cm boards on ebay.  I paid about $12 for ten of these http://www.ebay.com/itm/10pcs-7x9cm-Double-side-Protoboard-Circuit-Fibre-Glass-DIY-Prototype-PCB-Board-/371081793690.

you can put one under the Nucleo and an Arduino shield on top or another 7x9 board on top.

Signals are 5 V tolerant so many shields work.  I like the Adafruit 1.8" TFT with MicroSD and joystick https://www.adafruit.com/products/802.  ST uses it in examples so there is already STM32 code.

ST is really working to support this product with the STM32CubeMX configuration and code generation package.  There are frequent, about weekly, updates to add new boards, shields, and fix bugs.

STM32CubeMX is a big help.  It allows you to quickly configure all the pin and controller options and generates initialization code.  This is nice since Cortex M4 chips have so many options.  I then start with this code as a prototype and rewrite or replace the parts of ST firmware I don't like.

One reason I don't like Due is that it difficult to use Due other than the way the Arduino company setup the hardware and software.
37  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 28, 2014, 05:12:36 pm
I hope 4-bit SDIO DMA is much faster than 4-5 MB/sec.

Here is Due SPI DMA at 42 MHz with the new library:
Quote
Type is FAT32
File size 100MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 3915.83 KB/sec
Maximum latency: 34022 usec, Minimum Latency: 8190 usec, Avg Latency: 8365 usec

Starting read test.  Please wait up to a minute
Read 4261.15 KB/sec
Maximum latency: 8229 usec, Minimum Latency: 7619 usec, Avg Latency: 7688 usec

Notice DMA read gets a big boost.
38  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 28, 2014, 03:13:26 pm
42 MHz so full speed would be about 5 MB/sec.

On my new shiny bonus from a recent gig, an Agilent MSO-X 2202A with all features enabled, the gap between bytes for write is about 50% of time.  Read is longer since you must wait for data to shift in.

I am tempted to press on for 4-bit SDIO DMA.  I have designed the new library cache scheme for SDIO speeds.

Here is the result of a creating a 100 MB file on this 16 GB microSD www.amazon.com/SanDisk-MicroSDHC-Adapter-Frustration-Free-Packaging/dp/B009QZH7D8.  Max write latency for an 32 KB write increases to about 50 ms.  I suspect it would be less for writing to an already created contiguous file.  My cache is too small for this file's FAT.
Quote
Type is FAT32
File size 100 MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 2666.36 KB/sec
Maximum latency: 46845 usec, Minimum Latency: 12123 usec, Avg Latency: 12288 usec

Starting read test.  Please wait up to a minute
Read 2167.39 KB/sec
Maximum latency: 15768 usec, Minimum Latency: 15052 usec, Avg Latency: 15118 usec
 
39  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 28, 2014, 12:13:28 pm
Wow!  The NUCLEO-F401RE is really fast with just polled SPI.  I am using a stock Adafruit data logging shield.

I now have a new, not SdFat, file system library running well enough to do a first benchmark.

This is with a simple polled SPI library, not DMA.  Here is the first result, no attempt to optimize:
Quote
Type is FAT32
File size 10 MB
Buffer size 32768 bytes
Starting write test.  Please wait up to a minute
Write 2520.62 KB/sec
Maximum latency: 25258 usec, Minimum Latency: 12206 usec, Avg Latency: 12989 usec

Starting read test.  Please wait up to a minute
Read 2159.05 KB/sec
Maximum latency: 15712 usec, Minimum Latency: 15159 usec, Avg Latency: 15178 usec

Here are the SPI send and receive routines:
Code:
//------------------------------------------------------------------------------
/** SPI receive multiple bytes */
void SpiNative::receive(uint8_t* buf, size_t n) {
  for (size_t i = 0; i < n; i++) {
    SPI1->DR = 0XFF;
    while (!(SPI1->SR & SPI_FLAG_RXNE));
    buf[i] = SPI1->DR;
  }  
}
//------------------------------------------------------------------------------
// SPI send multiple bytes */
void SpiNative::send(const uint8_t* buf , size_t n) {
  for (size_t i = 0; i < n; i++) {
    SPI1->DR = buf[i];
    while (!(SPI1->SR & SPI_FLAG_TXE));
  }
  while (SPI1->SR & SPI_FLAG_BSY);
  // discard any receive data
  uint8_t tmp = SPI1->DR;
}
40  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 28, 2014, 08:32:10 am
pito,

I am looking at the external SDRAM as a large buffer for fast data logging of ADC data.

The ADC can be triggered by a timer and read by the DMA controller.  You can use DMA circular or double buffer mode with the ADC.  This will provide low sampling time jitter and avoid loss of data due to buffer management.

An SD on SPI or better, 4-bit SDIO, can run at the same time on a separate DMA channel.

Maybe a million samples per second.  That's 2 MB/sec and I have done 3 MB/sec to SD on Due with SPI DMA.  The DMA controllers each have 4 by 32 bit fifo to handle memory contention.

If the SDRAM is too slow, It still might work with on chip RAM.  Many SD cards have well under 100 ms max latency for streaming multi-block writes.  There is 256 KB of on chip RAM.
41  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 27, 2014, 02:21:16 pm
Quote
It is an SDRAM. The r/w access to it is about 6x slower than to the internal on-chip sram.
Still a lot faster than 8 MHz SPI SDRAM on AVR, like 100 times.

I plan on using it as an 8 MB RAM disk.
42  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 27, 2014, 12:54:57 pm
Quote
Have you tried the debugger yet?

It has SWD over USB which is the modern ARM replacement for JTAG.   Here is a link http://vedder.se/2012/12/debugging-the-stm32f4-using-openocd-gdb-and-eclipse/.

You can:
Quote
    Set hardware breakpoints
    See variable values when hitting the breakpoints
    Change variables, then continue
    Many other thingsā€¦

I don't find breakpoints very useful in complex embedded systems since they totally change the behavior of a system.

I use STM Studio and it works.  STM Studio is a run-time variables monitoring and visualization tool for STM8 and STM32 microcontrollers http://www.st.com/web/en/catalog/tools/PF251373.

STM Studio reads elf files to find symbols.
Quote
Reads on-the-fly (non intrusive) variables from RAM while application is running
Variable viewer - Real-time waveforms, oscilloscope-like graphs
TouchPoint viewer - Association of 2 variables, one on the X axis, one on the Y axis
You can also modify flash/RAM and view  tables of variables.
43  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 27, 2014, 08:24:29 am
From the STM32F411RE web page http://www.st.com/web/en/catalog/mmc/FM141/SC1169/SS1577/LN1877/PF260049
Quote
All I/O ports are 5 V-tolerant

Edit footnote:
Quote
5 V tolerant except when in analog mode or oscillator mode (for PC14, PC15, PH0 and PH1).
44  Development / Other Hardware Development / Re: Anyone tried ST Nucleo boards? on: June 27, 2014, 07:34:29 am
I continue to be pleased with the Nucleo boards.  I now program flash by drag and drop of the apps .bin file to the Nucleo folder.  This does not interrupt the connection to the serial monitor since there is a second STM32F103 that handles the serial monitor, programming flash, and debug.

There is a new NUCLEO-F411RE ($10.33 from Future Electronics).  It is faster, 100 MHz, has more SRAM, 128 KB, and 512 KB of flash.  There are three SPI controllers, three I2C controllers, and three UARTs.

I have tested the ADC on  these boards and it is at least 50 times faster than the Uno, 2.4 MSPS.  The 12-bit ADC seems to be very accurate.

I have almost finished porting a new FAT32/FAT16/FAT12 generic file system to the STM32.  I plan to support SD on SPI, SD on 4-bit SDIO, and USB flash drives.  4-bit SDIO should be very fast since it should run at 50 MHz. on the F411.

I also bought a 32F429IDISCOVERY board for $33.60 http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090.  256 KB internal RAM, 8 MB external SRAM, 2 MB flash, 180 MHz clock, 2.4" TFT touch screen.

The external SRAM has a 16-bit data bus and runs at 80 MHz.  Its three 12-bit ADCs can run in interleaved mode to digitize a signal at up to 7.2 MSPS.

Edit: Just checked and Future electronics now sells the 32F429IDISCOVERY  for $24.00, about the same as an Uno.
45  Using Arduino / Storage / Re: SDfat slow buffer flush on: June 21, 2014, 07:24:19 am
Quote
I miss capturing data during that period.
The problem is that write latency for SD cards can occasionally be very long.  This is caused by various housekeeping functions in the SD card.

SD cards must erase flash before writing.  SD cards perform wear leveling to increase the life of the SD card.

You must separate data capture from writing to the SD card and buffer data waiting to be written.  

You can capture data in an interrupt routine  like this example http://forum.arduino.cc/index.php?topic=228549.0 .

You can use a small RTOS like the nilSdLogger example in NilRTOS https://code.google.com/p/rtoslibs/downloads/list     NilRTOS20130720.zip.

Your current  program will have so much time jitter that there is no point in logging data this fast.  The information in a time series depends as much on the accuracy of the time of a data point as the accuracy of the value.

Many articles have been published about time jitter noise.  Google for "time jitter noise adc" for articles relevant to logging analog data.

If your data set is small, you could use a RAM disk http://forum.arduino.cc/index.php?topic=229485.0 or http://forum.arduino.cc/index.php?topic=236038.0.  You will still need to solve the time jitter problem.
Pages: 1 2 [3] 4 5 ... 107