Show Posts
Pages: 1 ... 55 56 [57] 58 59 ... 99
841  Development / Suggestions for the Arduino Project / Re: SoftwareSerial::flush() broken on: July 31, 2012, 09:08:42 am
Yes, flush() in SoftwareSerial still clears input.

The good news is you don't need it for output since output is not buffered in SoftwareSerial.

The bad news was that the functionality of flush was changed by the Arduino group instead of defining a new function.

Gradually libraries and programs are being fixed after this gratuitous change.  Maybe someday they will fix SoftwareSerial.
842  Topics / Science and Measurement / Re: Time and RTC libs - question on date and time integrity on: July 31, 2012, 08:55:28 am
All registers in the RTC must be read in the same I2C transaction.  I know RTClib https://github.com/adafruit/RTClib reads the DS1307 correctly.

I have written my own libraries for various RTC chips and all Maxim DS I2C chips have this feature:
Quote
When reading or writing the time and date registers, secondary (user) buffers are used to prevent errors when the internal registers update. When reading the time and date registers, the user buffers are synchronized to the internal registers on any I2C START. The time information is read from these secondary registers while the clock continues to run. This eliminates the need to re-read the registers in case the internal registers update during a read.
If your library has this bug, just read the time twice until the two values are equal.  Better yet find a new library.
843  Using Arduino / Storage / Re: Which SD library to create file with date? on: July 31, 2012, 08:54:04 am
pito,

See my reply in your original post about RTC libs.
844  Using Arduino / Storage / Re: SDFat - pulling out the card on: July 30, 2012, 05:53:04 pm
If you are short of pins, a better use for CS is to light an LED.  For normal operation the LED will be mostly lit with a little fast blinking during SD access.

You can indicate a fatal error by blinking with a half second period.  This won't be confused with normal operation.

During SD change you can turn the LED off when all files have been closed and it is OK to remove the SD.  The LED will light when the new SD has been initialized.
845  Using Arduino / Storage / Re: SdFat - card detection via CS support on: July 30, 2012, 04:05:47 pm
pito,

Even if you want to use the CS pullup idea on 3.3V, it is easier to just put the CS pin in input mode and read it than get SdFat in the way.

Code:
 pinMode(CS, INPUT);
  // wait for card to be inserted
  while (!digitalRead(CS)) {}

I use SdFat on SparkFun 3V3 boards with their SD microSD socket.  The socket has CD which is so much better than the pullup. https://www.sparkfun.com/products/544

I noticed my Olimex SDs seem to have signals for Write Protect and Card Detect.  Even the UEXT has these.
846  Using Arduino / Storage / Re: SDFat - pulling out the card on: July 30, 2012, 03:49:39 pm
A switch and LED is a great way to go if missing a point is OK.

Press the switch and wait for the LED.  Remove the card  and read it.  Insert the card and press the switch.  The LED goes out when init of the SD is successful.

In most cases card detect doesn't help much when you want to swap cards.  I have worked with a lot of users and in the end they don't even use the CD switch.

You can't just pull the card since you may corrupt the file or file system if flush/sync is not called.  This means you need to tell the app you want to remove the card.  If you install a switch to remove the card, you can use it to indicate the new card has been inserted.

People often fumble with inserting microSD cards.  They push them then try to feel if they are inserted which pop them back out.

A switch and LED is much more positive when the switch is also used to indicate card ready.  You just need to do a super debounce by waiting a second after the remove press is released before trusting the card ready press.
847  Using Arduino / Storage / Re: SdFat - card detection via CS support on: July 30, 2012, 03:41:31 pm
pito,

Yes I know what the SanDisk manual says.

It's just doesn't work for AVR with level shifters.

SS may already be in output mode due to other libraries.  It's just too messy to be worth doing in Arduino libraries.
848  Using Arduino / Storage / Re: SdFat - card detection via CS support on: July 30, 2012, 03:11:20 pm
pito,

It is not a good idea for Arduino. 

Arduino is 5V and SD is 3.3V so all good shields/modules have a level shifter.  You can't tell if a card is in the module because of the level shifter.

The Card Presence Switch on SD sockets is the correct way.

I now remember that ACMD42 connects or disconnects the 50K pullup on CS.  The problem is you can't send ACMD42 until the card is in SPI mode but CMD0 to put the card in SPI mode will fail if the card is not present.

So you can't toggle the pullup to make sure you seeing the card's 50K.

Since SS must be an output for SPI to work on AVR, other SPI libraries enable it so if SS is also CS (pin 10 on a 328) you should not make SS an input so you can't use the pullup idea.
849  Using Arduino / Storage / Re: Is my sd card compatible with SD.h on: July 30, 2012, 01:30:39 pm
SdFat and SD.h accept FAT16 and FAT32 if formatted to the SD format standard.

A card may work in a MAC/PC but not work with Arduino.

If you formatted it with an OS utility it may not work with an Arduino since many OS utilities do no comply with the SD format standard.  Use this formatter to insure the format complies with the SD standard https://www.sdcard.org/downloads/formatter_3/

In a PC, MAC, or camera the SD is accessed using the 4-bit SDIO bus.  In the Arduino the SD is accessed using the SPI bus.  It is possible that SPI access fails but you can access it via a PC/MAC.

The most common formatting problem is that the SD has a GUID Partition Table.  The SD standard require a MBR Partition Table and SD.h/ SdFat only accepts MBR.  Windows and OS X accept GUID Partition tables.  The above formatter will fix this problem.
850  Using Arduino / Storage / Re: SDFat - pulling out the card on: July 30, 2012, 09:43:29 am
The pullup is not a good idea.  CS is in output mode while the SD is in use.

If you are writing once every five minutes just init the card each time you write.

With the latest version of SdFat, sdfatlib20120719.zip http://code.google.com/p/sdfatlib/downloads/list.

I would do something like this:
Code:
#include <SdFat.h>
SdFat sd;
SdFile myFile;
// LED to flash just after write
const uint8_t LED_PIN = 3;
const uint8_t chipSelect = 10;
void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  if (!sd.begin(chipSelect)) sd.initErrorHalt();

  // open the file for write at end like the Native SD library
  if (!myFile.open("test.txt", O_WRITE | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  }
  // write your data
  myFile.println(millis());
  Serial.println('.');
  // close the file:
  myFile.close();
  // delay five minutes
  digitalWrite(LED_PIN, HIGH);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  delay(290000);
}
You can pull the card after the LED flash.
851  Using Arduino / Storage / Re: Which SD library to create file with date? on: July 30, 2012, 09:21:24 am
The version of SdFat used in 1.0 and 1.01 is the same old version used in 022 and before.  Only the SD.h wrapper has changed so this is still the best way.

If you had access to the SdFat API for files you could use the timestamp function to set all date/time fields on a per file basis.
Quote
bool SdBaseFile::timestamp    (    uint8_t     flags,
      uint16_t     year,
      uint8_t     month,
      uint8_t     day,
      uint8_t     hour,
      uint8_t     minute,
      uint8_t     second
   )       

Set a file's timestamps in its directory entry.

Parameters:
    [in]   flags   Values for flags are constructed by a bitwise-inclusive OR of flags from the following list

T_ACCESS - Set the file's last access date.

T_CREATE - Set the file's creation date and time.

T_WRITE - Set the file's last write/modification date and time.

Parameters:
    [in]   year   Valid range 1980 - 2107 inclusive.
    [in]   month   Valid range 1 - 12 inclusive.
    [in]   day   Valid range 1 - 31 inclusive.
    [in]   hour   Valid range 0 - 23 inclusive.
    [in]   minute   Valid range 0 - 59 inclusive.
    [in]   second   Valid range 0 - 59 inclusive

Note:
    It is possible to set an invalid date since there is no check for the number of days in a month.
    Modify and access timestamps may be overwritten if a date time callback function has been set by dateTimeCallback().

Returns:
    The value one, true, is returned for success and the value zero, false, is returned for failure.

Or copy timestamps from another file:
Quote
bool SdBaseFile::timestamp    (    SdBaseFile *     file   )    

Copy a file's timestamps

Parameters:
    [in]   file   File to copy timestamps from.

Note:
    Modify and access timestamps may be overwritten if a date time callback function has been set by dateTimeCallback().

Returns:
    The value one, true, is returned for success and the value zero, false, is returned for failure.


852  Using Arduino / Storage / Re: SdFat - card detection via CS support on: July 30, 2012, 09:11:38 am
Card Present is done in a number of ways.  A pullup, the card present switch,...

It is almost always easier to read the pin before calling the SD begin/init function than tell SdFat how Card Present is done and then have the result of a digitalRead() returned.

Some of the most popular shields have a 10K pullup on CS http://www.ladyada.net/images/logshield/logschemv1.png. and CS is always high in input mode.

Sometime resistor voltage dividers are used and the CS is always low in input mode.

In general pulling CS high is better than pulling CS weakly low and hoping all SD cards pull CS high.  This will cause fewer problems when the SPI bus is shared and another device is initialize before the SD.

Since Arduino is 5V, a level shifter is used on CS and you can't read the SD CS pin anyhow.
853  Using Arduino / Storage / Re: Micro-SD Card not formatted on: July 29, 2012, 01:30:45 pm
pito's advice is better than mine on caps since he is running SD cards on very fast systems.

I really like a pullup between 3.3V and MISO on the card.  This holds MISO high when there is no card and insures there won't be a false acceptance of CMD0, the first initialization command.  This can happen due to noise on MISO since I do thousands of retries waiting for the card to go ready.  Success for this command is a status of 0X01 which can easily happen with noise and no CRC. 

0XFF is busy so if MISO is held high, commands fails with a busy timeout.
854  Using Arduino / Storage / Re: Micro-SD Card not formatted on: July 29, 2012, 10:26:48 am
The SD status, errorData, has too many one bits to make sense.

For read CID the status 0X1F, would be:
Quote
• In idle state: The card is in idle state and running the initializing process.
• Erase reset: An erase sequence was cleared before executing because an out of erase sequence
command was received.
• Illegal command: An illegal command code was detected.
• Communication CRC error: The CRC check of the last command failed.
• Erase sequence error: An error in the sequence of erase commands occurred
This just can't be.  That's why I suspect MISO.
855  Using Arduino / Storage / Re: Micro-SD Card not formatted on: July 29, 2012, 09:17:23 am
It's definitely an SPI problem.  It appears to nearly work.  This may because SdFat does retries during initialization.

Arduino does not support hardware CRC but SdFat has software CRC which is normally disabled.

Could you please edit SdFatConfig.h at about line 35 and enable CRC like this:
Code:
#define USE_SD_CRC 2

Then run SdInfo again.  This may give a better indication of where the problem is.

It would be great if there was a way to connect MISO directly without the level shifter.  Most SD shields connect MISO directly.  This works even though a high level of 3.3V seem marginal as an input to the ATmega.  

The spec says the Min high input is 0.6Vcc.  Guess it works since the Max low input is 0.3Vcc.

Edit:

I checked some posting on AVR Freaks and the claim is:
Quote
The AVR clearly has much better specification, as at 5V vilmax is 0.42*Vcc=2.1V and vihmin is 0.52*Vcc=2.6V.
I guess this is why commercial shields work well.
Pages: 1 ... 55 56 [57] 58 59 ... 99