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.
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:
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);
}
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.
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.
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!
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:
If I have my alarm time that I need to set in this variable:
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)
//=====================================
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);
}
}
SouthernAtHeart:
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.