Forum: Mikrocontroller und Digitale Elektronik Backup Batterie ander RTC funktioniert nicht


von Bob (Gast)


Lesenswert?

Hallo liebe Gemeinde,

bin so langsam am verzweifeln. Möchte meine RTC mit einer Backup 
Batterie versorgen und habe meiner Meinung nach das Sketch so angepasst 
das es nach einem Stromreset funktionieren sollte. Aber sobald das 
Arduino wieder hochgefahren ist , beginnt der Timmer wieder von neuem ( 
Vorgabe aus dem Sketch.

Vielleicht sieht einer von euch ob ich etwas übersehen habe.

Danke schon mal im Voraus

#include "I2C.h"

const int MCP7940_I2C  = 0x6F;  // I2C Address for the RTC

const int REG_RTCSEC   = 0x00;  // Register Address: Time Second
const int REG_RTCMIN   = 0x01;  // Register Address: Time Minute
const int REG_RTCHOUR  = 0x02;  // Register Address: Time Hour
const int REG_RTCWKDAY = 0x03;  // Register Address: Date Day of Week
const int REG_RTCDATE  = 0x04;  // Register Address: Date Day
const int REG_RTCMTH   = 0x05;  // Register Address: Date Month
const int REG_RTCYEAR  = 0x06;  // Register Address: Date Year

byte      timeStamp[7];         // Byte array holding a full time stamp.

// Array position is the same as the register address.

 void init_MCP7940()
{
  byte    registerValue = 0x00;    // Holds the received register value
  byte    twelveHour    = 0x00;    // 0 = 24 Hour Clock Mode / 1 = 12 
Hour Clock Mode
  byte    startClock    = 0x01;    // 0 = Start Oscillator   / 1 = Stop 
Oscillator
  byte    batEnable     = 0x01;    // 0 = Disable Battery Backup / 1 = 
Enable Battery Backup

  // Turn on/off: 12 hour vs. 24 hour clock
  I2c.read    (MCP7940_I2C, REG_RTCHOUR, 1);
  registerValue = I2c.receive();
  if (twelveHour == 0x00) I2c.write (MCP7940_I2C, REG_RTCHOUR, bitClear 
(registerValue, 6));
  if (twelveHour == 0x01) I2c.write (MCP7940_I2C, REG_RTCHOUR, bitSet 
(registerValue, 6));

  // Turn on/off: Oscillator (starts the clock)
  I2c.read    (MCP7940_I2C, REG_RTCSEC, 1);
  registerValue = I2c.receive();
  if (startClock == 0x00) I2c.write (MCP7940_I2C, REG_RTCSEC, bitClear 
(registerValue, 7));
  if (startClock == 0x01) I2c.write (MCP7940_I2C, REG_RTCSEC, bitSet 
(registerValue, 7));

  // Turn on/off: Battery Enable
  I2c.read    (MCP7940_I2C, REG_RTCWKDAY, 1);
  registerValue = I2c.receive();
  if (batEnable == 0x00) I2c.write (MCP7940_I2C, REG_RTCWKDAY, bitClear 
(registerValue, 3));
  if (batEnable == 0x01) I2c.write (MCP7940_I2C, REG_RTCWKDAY, bitSet 
(registerValue, 3));
}


byte convertToBcd(byte byteDecimal)
{

  return (byteDecimal / 10) << 4 | (byteDecimal % 10);

}

byte convertFromBcd(byte byteBCD) {

  byte byteMSB = 0;
  byte byteLSB = 0;

  byteMSB      = (byteBCD & B11110000) >> 4;
  byteLSB      = (byteBCD & B00001111);

  return       ((byteMSB * 10) + byteLSB);
}

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.