RTC1302

Hallo Leute, ich versuche seit nunmehr 6 Stunden mein RTC1302 anständig ans laufen zu bringen.

Mein Code sieht wie folgt aus.
Ich benutze ein Unov3

#include <DS1302.h>

// Init the DS1302
// DS1302 rtc([CE/RST], [I/O/Dat], [CLOCK/CLK]);
DS1302 rtc(2, 3, 4);

void setup() {
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(true);
  
  // Setup Serial connection
  Serial.begin(9600);

  //The following lines can be commented out to use the values already stored in the DS1302
  //rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
}

void loop() {
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

Mein serieller Monitor spukt dies aus:

Wie Ihr seht ist nur jeder zweite Wert richtig, ich habe wirklich alles versucht, auch andere librarys...
Vielleicht kann ja hier jemand helfen.

Liebe Grüße Chris

Leider sehen wir nichts. :wink:
Das Bild ist nicht zu erkennen.

Besser?

ChrisBoy:
Besser?

Ja...

Ich kenne diese RTC nicht habe aber in einem Beispielsketch folgenden Befehl gesehen.

setSyncProvider(RTC.get); // the function to get the time from the RTC

Den vermisse ich bei dir.
Das liegt vermutlich an der verwendeten Library.

Hier der Sketch:

http://playground.arduino.cc/Main/DS1302RTC

Bei meiner lib sehen die rtc.get Befehle etwas anders aus, sollten aber dasselbe tun.
Die von dir verlinkte habe ich nicht benutzt, da man da auch den gnd und vcc Pin deklarieren muss.
Leider weiß ich nicht welche Nummer die auf meinem Uno haben.
Wenn mir hier jemand weiterhelfen kann, probiere ich es nochmal so.

Dann kann ich mein heute ans I2C interface gelötete 1602 direkt mittesten :stuck_out_tongue:

ChrisBoy:
Die von dir verlinkte habe ich nicht benutzt, da man da auch den gnd und vcc Pin deklarieren muss.
Leider weiß ich nicht welche Nummer die auf meinem Uno haben.

Das mit GND und VCC ist doch nur optional.

// Optional connection for RTC module
#define DS1302_GND_PIN 33
#define DS1302_VCC_PIN 35

Dann kann ich mein heute ans I2C interface gelötete 1602 direkt mittesten :stuck_out_tongue:

Wenn du das LCD schon mit I2C hast, warum dann keine RTC mit I2C, da könntest du direkt Ports sparen.

Zumal die DS3231 sehr viel genauer ist.

Ports habe ich genug, muss ja auch irgendwie mit dem 1302 klappen, zumal ich den zu Hause habe?!

Noch jemand einen Ratschlag?

ChrisBoy:
Ports habe ich genug, muss ja auch irgendwie mit dem 1302 klappen, zumal ich den zu Hause habe?!

Es geht nicht um die Ports, sondern dass man einheitliche Anschlüsse verwendet.
Das macht es einfacher.
Erst recht, wenn man erst anfängt.

Noch jemand einen Ratschlag?

Da du bisher noch nichts über die Library geschrieben hast, versuche es doch mal mit einer "aktuellen".
Ich vermute, dass die von dir verwendete zu alt ist.

Da du bisher noch nichts über die Library geschrieben hast

Sorry, ich habe alle möglichen durchprobiert wo nur ansatzweise 1302 bei Stand :stuck_out_tongue:
Hast du vielleicht eine Empfehlung für eine Anständige?

Poste bald auch mal meine gesammten Projekte für eine Terrariensteuerung, einen Bluetooth RGB Strip und eine WLAN Lampe :slight_smile:
Vorher soll ich nur die ganze Zeit nehmen??

Liebe Grüße

Hallo,

hier findest du die aktuellste Library zur DS1302.

Inkl. Beispiele.

HotSystems:
Zumal die DS3231 sehr viel genauer ist.

Ich gebe noch nicht auf, habe mir aber vorsichtshalber das DS3231 für 1,65€
aus China bestellt...
Halte euch auf dem Laufenden!

ChrisBoy:
Ich gebe noch nicht auf, habe mir aber vorsichtshalber das DS3231 für 1,65€
aus China bestellt...
Halte euch auf dem Laufenden!

Aus meiner Sicht eine sehr gut Entscheidung.

Aber die DS1302 muss man doch auch zum Laufen bringen. ???

So wieder schlechte Neuigkeiten...

Habe den Beispielcode verwendet um den RAM zu clearen und hello world zu printen.
Angeschlossen an die digital Pins 4 5 6.
Bekomme folgendes geprinted:

[00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]

Wo ist der Unterschied zu den Pins 2 3 4, da bekomme ich folgendes geprinted:

[34][65][36][36][6F][10][77][6F][39][36][32][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00][00]
´26¶7�»7962

Mhmm... Hier noch der Code dazu.

#include <stdio.h>
#include <DS1302.h>

namespace {

// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip. See the DS1302
// datasheet:
//
//   http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin   = 4;  // Chip Enable
const int kIoPin    = 5;  // Input/Output
const int kSclkPin = 6;  // Serial Clock

DS1302 rtc(kCePin, kIoPin, kSclkPin);

}  // namespace

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

  rtc.writeProtect(false);

  // Clear all RAM bytes, using the byte interface.
  for (int i = 0; i < DS1302::kRamSize; ++i) {
    rtc.writeRam(i, 0x00);
  }

  // Write a string using the bulk interface.
  static const char kHelloWorld[] = "hello world";
  rtc.writeRamBulk((uint8_t*)kHelloWorld, sizeof(kHelloWorld) - 1);
}

void loop() {
  char buf[32];

  // Print the RAM byte values as hex using the byte interface.
  for (int i = 0; i < DS1302::kRamSize; ++i) {
    snprintf(buf, sizeof(buf), "[%02X]", rtc.readRam(i));
    Serial.print(buf);
  }
  Serial.println();

  // Print the RAM byte values as ASCII using the bulk interface.
  uint8_t ram[DS1302::kRamSize];
  rtc.readRamBulk(ram, DS1302::kRamSize);
  Serial.println((const char*)ram);

  delay(3000);
}

Dann habe ich den set_clock Beispielcode probiert

// Example sketch for interfacing with the DS1302 timekeeping chip.
//
// Copyright (c) 2009, Matt Sparks
// All rights reserved.
//
// http://quadpoint.org/projects/arduino-ds1302
#include <stdio.h>
#include <DS1302.h>

namespace {

// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip. See the DS1302
// datasheet:
//
//   http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin   = 4;  // Chip Enable
const int kIoPin   = 5;  // Input/Output
const int kSclkPin = 6;  // Serial Clock

// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Sunday";
    case Time::kMonday: return "Monday";
    case Time::kTuesday: return "Tuesday";
    case Time::kWednesday: return "Wednesday";
    case Time::kThursday: return "Thursday";
    case Time::kFriday: return "Friday";
    case Time::kSaturday: return "Saturday";
  }
  return "(unknown day)";
}

void printTime() {
  // Get the current time and date from the chip.
  Time t = rtc.time();

  // Name the day of the week.
  const String day = dayAsString(t.day);

  // Format the time and date and insert into the temporary buffer.
  char buf[50];
  snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
           day.c_str(),
           t.yr, t.mon, t.date,
           t.hr, t.min, t.sec);

  // Print the formatted string to serial so we can see the time.
  Serial.println(buf);
}

}  // namespace

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

  // Initialize a new chip by turning off write protection and clearing the
  // clock halt flag. These methods needn't always be called. See the DS1302
  // datasheet for details.
  rtc.writeProtect(false);
  rtc.halt(false);

  // Make a new time object to set the date and time.
  // Sunday, September 22, 2013 at 01:38:50.
  Time t(2013, 9, 22, 1, 38, 50, Time::kSunday);

  // Set the time and date on the chip.
  rtc.time(t);
}

// Loop and print the time every second.
void loop() {
  printTime();
  delay(1000);
}

Hier als Antwort wie gehabt, jeder zweite Wert ist falsch?

(unknown day) 2009-84-91 00:102:28
Sunday 2013-09-22 01:38:51
(unknown day) 2009-84-91 00:102:29
Sunday 2013-09-22 01:38:53
(unknown day) 2009-84-91 00:102:30
Sunday 2013-09-22 01:38:55
(unknown day) 2009-84-91 00:102:31
Sunday 2013-09-22 01:38:57
(unknown day) 2009-84-91 00:102:32
Sunday 2013-09-22 01:38:59
(unknown day) 2009-84-91 00:102:00

Langsam verzweifel ich!
Glaube das Ding fällt gleich ausversehen ins Klo...