Pages: [1]   Go Down
Author Topic: Understand bits/bytes, and reading the datasheet for the DS3234  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Trying to learn a little about the DS3234.  This writing data to the registery is all new to me, but I've figured out about setting different bits high or low, I think.
https://www.sparkfun.com/datasheets/BreakoutBoards/DS3234.pdf

On page 14:
I would want the oscillator to be running (Bit 7), to give good time keeping, correct?  So it would be 0.
I will be using alarm 1, not the square wave output, so bit 3,4,5,6 are of no importance, so they are 0.
Bit 0 is set to 1 to enable  alarm 1.
Bit 0 = 1
Bit 2 = 4
_______
= 5 = 0x05

So I would initiate it like this:
Code:
int RTC_init(){
 pinMode(cs,OUTPUT); // chip select
 SPI.begin();  // start the SPI library:
 SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE1); // I won't be using SPI for anything else
 //set control register
 digitalWrite(cs, LOW);  
 SPI.transfer(0x8E);
 SPI.transfer(0x05); //Alarm1 Enabled
 digitalWrite(cs, HIGH);
 delay(10);
}

Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I might set the alarm registers (0x87-0x8A) first, before enabling the alarm, but it looks like you have the basics sussed out. If the EOSC bit is set to 1, when Vcc power is not applied, the RTC won't keep time at all.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I might set the alarm registers (0x87-0x8A) first, before enabling the alarm, but it looks like you have the basics sussed out. If the EOSC bit is set to 1, when Vcc power is not applied, the RTC won't keep time at all.

Ok, but I'll be changing the alarm time 2x a day. Should I resend this after each time I change the alarm?
Code:
SPI.transfer(0x8E);
SPI.transfer(0x05); //Alarm1 Enabled
Or is just the first initial time good enough?
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The control register should stay set, so does not to be reset every time the alarm is changed. I was thinking that there is a remote chance, not knowing the state of the alarm registers, that setting the A1IE bit could generate an unwanted alarm.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, now I see why you said that.  ...be sure the alarm's not set for a bad time before turning it on.
Now to figure out how to set the alarm.  I'll take a stab at it and then ask for help/corrections.  Come back in 20 minutes!
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Setting the alarm seems WAY harder than reading the time.
I understand most of this example sketch from Sparkfun's site:
http://dlnmh9ip6v2uc.cloudfront.net/datasheets/BreakoutBoards/DS3234_Example_Code.pde

I will need the alarm to sound when the hours, minutes, and seconds match, so I will need to set Bit 7 (A1M4) to 1 on 8Ah. 
I gather this from Table 2, Page 13:
https://www.sparkfun.com/datasheets/BreakoutBoards/DS3234.pdf


If I have my alarm time that I need to set in this variable:
Code:
int AlarmTime [3]; //second,minute,hour
Can someone show me how to set the alarm registers.
It must be similar to this (setting the time)
Code:
//=====================================
int SetTimeDate(int d, int mo, int y, int h, int mi, int s){
int TimeDate [7]={s,mi,h,0,d,mo,y};
for(int i=0; i<=6;i++){
if(i==3)
i++;
int b= TimeDate[i]/10;
int a= TimeDate[i]-b*10;
if(i==2){
if (b==2)
b=B00000010;
else if (b==1)
b=B00000001;
}
TimeDate[i]= a+(b<<4);
 
digitalWrite(cs, LOW);
SPI.transfer(i+0x80);
SPI.transfer(TimeDate[i]);       
digitalWrite(cs, HIGH);
  }
}
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Setting the alarm seems WAY harder than reading the time.

It does, doesn't it? All those AxMy bits, spread over three or four registers. I wrote a library for the DS3232, check my approach there. It probably wouldn't be a huge job to adapt the library for the DS3234, the I2C calls (Wire library) would need to be changed to SPI. The registers are very similar if not identical.

I'm sure there are DS3234 libraries out there too, though.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found a library that looks hopeful!
Logged

Pages: [1]   Go Up
Jump to: