Show Posts
Pages: 1 ... 54 55 [56] 57 58 ... 99
826  Topics / Science and Measurement / Re: Time and RTC libs - question on date and time integrity on: July 31, 2012, 12:30:31 pm
RTClib here https://github.com/jcw/rtclib read all PCF8563 registers correctly:
Code:
DateTime RTC_PCF8563::now() {
    Wire.beginTransmission(PCF8563_ADDRESS);
    Wire.write(PCF8563_SEC_ADDR);
    Wire.endTransmission();

    Wire.requestFrom(PCF8563_ADDRESS, 7);
    uint8_t ss = bcd2bin(Wire.read() & 0x7F);
    uint8_t mm = bcd2bin(Wire.read() & 0x7F);
    uint8_t hh = bcd2bin(Wire.read() & 0x3F);
    uint8_t d = bcd2bin(Wire.read() & 0x3F);
    Wire.read();
    uint8_t m = bcd2bin(Wire.read()& 0x1F);
    uint16_t y = bcd2bin(Wire.read()) + 2000;
    
    return DateTime (y, m, d, hh, mm, ss);
}

RTClib also works with DS1307.  DS1307 libraries often work with some ot the other Maxim I2C RTC chips.
827  Development / Suggestions for the Arduino Project / Re: SoftwareSerial::flush() broken on: July 31, 2012, 12:23:41 pm
I believe pre 1.0 flush() discarded all characters in the input buffer.

I think most people use something like this:
Code:
  while (Serial.read() >= 0) {}


If you want to discard all but n characters you could do this:
Code:
while (Serial.available() > n) Serial.read();

For n == 0 this is like the old flush().

I understand the Arduino group is thinking of bringing back the old flush with a new name.  Way to go team!
828  Development / Suggestions for the Arduino Project / Re: SoftwareSerial::flush() broken on: July 31, 2012, 09:58:14 am
Other bad news about flush().  HardwareSerial flush of output doesn't work correctly either.  The documentations says:
Quote
flush()
Description

Waits for the transmission of outgoing serial data to complete.

It only waits for the SRAM buffer to be empty.  There may be two characters that have not been sent, one in the shift register and one in the UART data buffer.

If you call Serial.end() after flush(), these characters will be lost or garbled. Anything that resets the UART or changes the UART will lose these characters.  

This can kill protocols where you send at various speeds.  To set the speed of a SiRF GPS you send a message at every baud rate that tells it what baud rate you want to use.
829  Topics / Science and Measurement / Re: Time and RTC libs - question on date and time integrity on: July 31, 2012, 09:30:21 am
pito,

I also wrote my own replacement for Wire for I2C master access to devices so I have better control over the I2C protocol. 

I assume Wire does the read correctly as a single transaction but it is very complex with interrupts and both slave and master support.
830  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.
831  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.
832  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.
833  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.
834  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.
835  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.
836  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.
837  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.
838  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.
839  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.
840  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.


Pages: 1 ... 54 55 [56] 57 58 ... 99