SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By Maksim_maksim
#184733
Hi all. I wrote code for RTC x1226, bun dosn't work (((
Code: Select all
#include <Wire.h>
#include <avr/interrupt.h>
byte seconds, hours, minutes, date, months, years, statusReg;

byte a0,a1,a2,a3,a4,a5,a6,a7,a8,i;
byte a[64];


void setup () {
  
  Serial.begin(9600);
  Wire.begin();
  
  Wire.beginTransmission(0x6F); 
  Wire.write(0xde);
//  Wire.write(0x00);
  Wire.write(0x3f); //Int Register
  Wire.write(0x02);
  Wire.endTransmission();
  
   Wire.beginTransmission(0x6F); 
  Wire.write(0xde);
 // Wire.write(0x00);
  Wire.write(0x3f); //Int Register
  Wire.write(0x06);
  Wire.endTransmission();
  
  Wire.beginTransmission(0x6F); 
  Wire.write(0xde);
//  Wire.write(0x00);
  Wire.write(0x11); //Int Register
  Wire.write(0x08);
  Wire.endTransmission();
  
  delay(10);
  
   Wire.beginTransmission(0x6F); 
  Wire.write(0xde);
  Wire.write(0x00);
 Wire.write(0x3f); //Int Register
  Wire.write(0x00);
  Wire.endTransmission();
}


void loop () {
    
  Wire.beginTransmission(0x6F); 
  Wire.write(0xae);
//  Wire.write(0x00);
  Wire.write(0x00);
  Wire.write(0x00);
  Wire.write(55);  
  Wire.endTransmission();
  
  
    Wire.beginTransmission(0x6F); 
  Wire.write(0xaf);
//  Wire.write(0x00);
  Wire.write(0x00);
  Wire.write(0x00);
//  Wire.write(55);  

 Serial.println(Wire.read());
  Serial.println("------"); 
  
//  Wire.requestFrom(0x6f,1); // now get the byte of data...


  for (i=0; i<=8; i++){
  a[i]=Wire.read();
    Serial.print(a[i]);
    Serial.print(",");
  }
  
 Wire.endTransmission();        
 // Serial.println(statusReg);
 Serial.println("------"); 
  delay(1000);
  
 }
 
 byte readStatusReg(byte val){

  Wire.beginTransmission(0x6f);
  Wire.write(0x3f); // read status reg to clr bits
  Wire.endTransmission();
  Wire.requestFrom(0x6f,1); // now get the byte of data...
  statusReg=Wire.read();
  return(statusReg);

}
SPI-scaner find this RTC on adress 0x6F