Pages: [1]   Go Down
Author Topic: i2c rtc writing to addresses need help  (Read 966 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, need help please confusion setting in, chip in particular is this ISL12057 @ http://www.intersil.com/content/dam/Intersil/documents/fn67/fn6755.pdf. the rtc itself works fine with the rtc library for the 1307, got the time set np, im trying to set the alarm (int2) for every minute. the datasheet is clear enough but how would you write this?
like this im getting nothing. how would i write to the config register? thanks in advance.
Code:
Wire.beginTransmission(0x68);
Wire.write(0x0B>>8);
Wire.write(0x0B & 0xFF);
Wire.write(0x80);
Wire.endTransmission();
with 0Bh being the addr and 80h being the data.

or
Code:
Wire.beginTransmission(0x68);
Wire.write(0x0b); //addr
Wire.write(0x80); //data
Wire.write(0x0c); //addr
Wire.write(0x80); //data
Wire.write(0x0d); //addr
Wire.write(0x80); //data
Wire.endTransmission();

im probably not initializing them correctly in the config register, any help appreciated.
« Last Edit: June 14, 2013, 08:54:01 pm by grendle » Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1661
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Wire.write(0x0B>>8);
This isn't right.
Code:
(0xB >> 8)
is zero. When writing an address to the chip you only write one byte (i.e. only 0x0B), not two. Follow that with whatever data is required.

Pete
« Last Edit: June 14, 2013, 09:38:30 pm by el_supremo » Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ya im still doing something wrong. can someone more experienced pick up one of these from intersil, for free, just sample one out, their soic8. i cant figure this out.
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1661
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Once you have set the address register you can write a consecutive sequence of data. To set Alarm2 to fire every minute use this:
Code:
Wire.beginTransmission(0x68);
Wire.write(0x0b); //addr
Wire.write(0x80); //data to 0x0b
Wire.write(0x80); //data to 0x0c
Wire.write(0x80); //data to 0x0d
Wire.endTransmission();

BTW. The registers for the ISL12057 look very similar to the DS3234/DS3231 so code for those should work with minimal or no tweaking on ISL12057.

Pete
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you very much, sweet, im gonna set it up in a minute and experiment some more. oh also i meant someone more experienced then me, not you supremo, i just re-read that and it didnt sound right, sorry. also, one more thing, im running 3.3 v for supply, im not experienced enough with datasheets, is sda and scl 5 v tolerant?
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1661
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is sda and scl 5 v tolerant?
The datasheet says absolute maximum on those two pins is 6V and maximum operating voltage on those is 5.5V so they should be OK with 5V.

Pete
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok great thx. i got it working using an rtclib https://github.com/MrAlvin/RTClib here, based on your suggestion, i used the part of the library for the dsDS3231. alarm fired. now just gotta figure out how to set for every minute as the examples set for a specific time, but ive made tons of progress thanks to you. appreciate it much supremo.
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1661
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a vague memory of trying to figure out that library quite some time ago.
Instead of calling setA2Time in the library, try using the code in my previous message to set alarm2 to fire every minute.

Pete
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well, its just like you suspected. works great with your code smiley, on a side note however, with this library, physical int2pin is pin 1 and pin1 is 2. they are reversed lol. but all is well and im totally happy now. now i can incorporate this piece into my low voltage projects (working on weatherstation). much thanks supremo!!  smiley-grin
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 148
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just fyi i got it working correctly using the normal rtc library everyone uses for the 1307 (ie normal version since the other lib only worked on 1.0.2 and below) anyway, fires every second, clears alarm second later. thanks to supremo for figuring this out for me.

Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
  //  pinMode(16, OUTPUT);
  //  digitalWrite(16, LOW);
  //  pinMode(17, OUTPUT);
  //  digitalWrite(17, HIGH);//use this for piggyback

  Serial.begin(9600);
  Wire.begin();
  RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  RTC.adjust(DateTime(__DATE__, __TIME__));



  Wire.beginTransmission(0x68);     //supremos code
  Wire.write(0x0b); //alarm2 addr   // writes 0x80 to 3 registers which sets alarm 2 fire off when seconds register == 00 ie once a minute
  Wire.write(0x80); //data to 0x0b
  Wire.write(0x80); //data to 0x0c
  Wire.write(0x80); //data to 0x0d
  Wire.endTransmission();

}

void loop () {
  Wire.beginTransmission(0x68);
  Wire.write(0x0f); //status reg addr
  Wire.endTransmission();
  Wire.requestFrom(0x68,1); // read status register to see if alarm fired
  byte statusBuffer=Wire.read();
  byte y = bitRead(statusBuffer,1); //af2 bit indicates alarm2 fired if ==1
  if (y==1)
  {
    Wire.beginTransmission(0x68); // clear alarm af2 bit
    Wire.write(0x0F); //status register normally B10000000, only bits 0 and 1 can be written to, only with a 0, to clr alarms
    Wire.write(0x80);
    Wire.endTransmission();
  }
  gettime();
  delay(1000);

}

void gettime(){
  DateTime now = RTC.now();
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(' ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();

}

Logged

Pages: [1]   Go Up
Jump to: