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:
void File::rewindDirectory(void) { 
  if (isDirectory())

Here is the SdFat rewind function:
  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:"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.
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:
Sd2Card card;
SdVolume vol;
SdFile root;

They are useful to diagnose problems but just use the SD object like this example:
/* 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:
   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!");
  Serial.println("initialization done.");
  // open the file.
  myFile ="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:
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  // re-open the file for reading:
  myFile ="test.txt");
  if (myFile) {
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    // close the file:
  } 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:
Initializing SD card...initialization done.
Writing to test.txt...done.
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.
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.

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:
  Serial.println("card initialized.");

With this:
  Serial.println("card initialized.");
  File testFile ="tar.txt", FILE_WRITE);

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

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  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:
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  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.
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:
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:
/** 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

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
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
Have you tried the debugger yet?

It has SWD over USB which is the modern ARM replacement for JTAG.   Here is a link

You can:
    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

STM Studio reads elf files to find symbols.
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
All I/O ports are 5 V-tolerant

Edit footnote:
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  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
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 .

You can use a small RTOS like the nilSdLogger example in NilRTOS

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 or  You will still need to solve the time jitter problem.
Pages: 1 2 [3] 4 5 ... 107