Pages: [1]   Go Down
Author Topic: ds1904  (Read 513 times)
0 Members and 1 Guest are viewing this topic.
milano, italy
Offline Offline
Sr. Member
****
Karma: 1
Posts: 493
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ho a casa un ds1904 un RTC della maxim in formato ibutton. ho cercato un po come farlo funzionare e naturalmente sul datasheet ce tutto, ma volevo sapere se c'era qualche libreria gia pronta per utilizzarlo. ce qualcuno che puo darmi una mano?   smiley

c
Logged

BZ (I)
Offline Offline
Brattain Member
*****
Karma: 251
Posts: 21254
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ciao camba192

Hai provato di cercare con un motore di ricerca "arduino ds1904" ?

Ciao Uwe
Logged

milano, italy
Offline Offline
Sr. Member
****
Karma: 1
Posts: 493
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

si come gia detto ho cercato ma non sono riuscito a capire molto da questo topic che ho trovato .. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1248727122/0

c
Logged

milano, italy
Offline Offline
Sr. Member
****
Karma: 1
Posts: 493
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok ho risolto grazie lo stesso  smiley

c
Logged

BZ (I)
Offline Offline
Brattain Member
*****
Karma: 251
Posts: 21254
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Allora spiegalo per favore cosí puoi aiutare altri che vorranno usare il DS1904.
Ciao Uwe
Logged

milano, italy
Offline Offline
Sr. Member
****
Karma: 1
Posts: 493
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ho usato questo codice
Code:
#include <OneWire.h>

// DS1904 Real Time Clock iButton I/O
OneWire ds(10);  // on pin 10

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  int rtc;
  int  a,e,g,s,m,o;
  byte i;
  byte present = 0;
  byte data[8];
  byte addr[8];
  

  if ( !ds.search(addr)) {
      /*Serial.print("No more addresses found.\n");*/
      ds.reset_search();
      delay(500);  // for readability
      return;
  }
/*
  Serial.print("ROM: ");
  for( i = 0; i < 8; i++) {
    Serial.print(addr[i], HEX);
    Serial.print(" ");
  }
*/
  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] != 0x24) {
      Serial.print("\t\tDevice is not a DS1904 family device.\n");
      return;
  }

/*
  // write!
  Serial.println("writing to RTC...");
  present = ds.reset();
  ds.select(addr);
  ds.write(0x99,1);   // write RTC
  ds.write(0xAC);
  ds.write(0x00);
  ds.write(0x00);
  ds.write(0x00);
  ds.write(0x00);
  present = ds.reset();
  delay(1500);     // unknown if wait needed
*/

  // read!
  present = ds.reset();
  ds.select(addr);
  ds.write(0x66,1);   // read RTC
/*
  Serial.print("PR: ");
  Serial.print(present, HEX);
*/  
  for ( i = 0; i < 5; i++) {
    data[i] = ds.read();
  }
  /*
  Serial.print(" CTRL BYTE:  ");
  Serial.print(data[0], BIN);*/
   rtc = ((uint32_t)data[1]); //LSB
  rtc |= ((uint32_t)data[2]) << 8;
  rtc |= ((uint32_t)data[3]) << 16;
  rtc |= ((uint32_t)data[4]) << 24;  //MSB
  
  g=rtc/86400;
  Serial.print("\n");
  Serial.print(g, DEC);
  o=rtc/3600;
  o=o-g*24;
  Serial.print("  ");
  Serial.print(o, DEC);
  m=rtc/60;
  m=m-o*60-g*1440;
  Serial.print(":");
  Serial.print(m, DEC);
  s=rtc;
  s=s-m*60-o*3600-g*86400;
  Serial.print(":");
  Serial.print(s, DEC);
  Serial.print(" ");
  
  


}
 

che manda in seriale i giorni  ora:mionuti:secondi

la libreria si puo scaricare a questo indirizzo http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip   smiley

c
« Last Edit: September 28, 2010, 05:12:28 pm by camba192 » Logged

Pages: [1]   Go Up
Jump to: