DS3234 and Arduino

Hey. So I've been googling how to connect my DS3234 to the Arduino.
I found what appears to be an excellent library here Google Code Archive - Long-term storage for Google Code Project Hosting.

I'm using this breakout board for the ds3234

I think I connect the clk pin on the ds3234 to the A5 pin on my arduino, but otherwise I am lost.
What do I do with the MISO, MOSI, and SS pins on the DS3234 breakout?
Thanks!

Are you using the 3234 or the 3231? That library you linked to is for the 3231 which uses the I2C interface. The 3234 which it sounds like you are using communicates using spi, so take a look at SPI - Arduino Reference.

Right, that lib is for the I2C version. Once you've learned about the SPI bus per the link above, you can check out my DS3234 port of the JeeLabs RTC library.

Maniac and others,

I'm hoping for some help here. I've been playing with arduino for a few months now and understand the basics of wiring and coding. I have a friend who is a programmer as well helping. We have run into a problem though, I've downloaded the rtclib from github as well as the examples. I have wired the ds3234 to the mega as follows:
RTC = Mega
ss 8
miso mosi
mosi miso
clk sck
sqw open
vcc tried both 3.3 & 5v
gnd gnd

I've tried wiring the miso/mosi directly instead of crossing them and still get the following results.
RTClib/examples/ds3234/
RTC is NOT running!
Setting time to... Apr 13 2012 11:37:28
Dec 31 2165 23:60:60
since midnight 1/1/1970 = 1890322364s = 21878d
now + 7d + 30s: Dec 02 2029 17:33:14

since midnight 1/1/1970 = 2313941504s = 26781d
now + 7d + 30s: May 06 2043 17:32:14

since midnight 1/1/1970 = 2313941504s = 26781d
now + 7d + 30s: May 06 2043 17:32:14

Dec 31 2165 23:60:60
since midnight 1/1/1970 = 1890322364s = 21878d
now + 7d + 30s: Dec 02 2029 17:33:14

since midnight 1/1/1970 = 2313941504s = 26781d
now + 7d + 30s: May 06 2043 17:32:14

since midnight 1/1/1970 = 2313941504s = 26781d
now + 7d + 30s: May 06 2043 17:32:14

Dec 31 2021 23:45:60
since midnight 1/1/1970 = 1640994360s = 18992d
now + 7d + 30s: Jan 07 2022 23:46:30

Please help, The only change in your code that i have made was the baud to 115200L.
3234 test code - Pastebin.com this is the code

You must initialize pin 10 as an output, even if you don't use it, otherwise the Arduino SPI will be in slave mode.
I have the DeadOn breakout board too and I wired it up like this:
Pin 13 SCK
Pin 12 MISO
Pin 11 MOSI
Pin 10 SS

Worked first time.
Pete

@EL,

I'm using a Mega 2560, so the pin assignments are different. I have tried using pin53 SS on the mega and still the same results.

Lee

Sorry, I overlooked that you were using a Mega.
When wiring it up, MOSI on the Mega (51) goes to MOSI on the RTC. MISO (Mega 50) goes to MISO on the RTC. Mega pin 52 goes to CLK on the RTC.
You don't have to use pin 53 as SS but whether you do or not, you should have this statement in setup() BEFORE the SPI.begin().

  pinMode(53, OUTPUT);

I assume the SPI library on the Mega is the same as on earlier boards in which case it will require that pin 53 must never be an input at any time during the use of the SPI library.

Pete

El,

Thanks for the help. You were correct I had read on another forum about ensuring that Miso, Mosi went to each other. I was under the impression that they should be crossed initially. Even without changing the code both from Maniac and Sparkfuns example sketch worked right off after fixing the wiring.

Any thoughts on setting the alarm, and stopping it from resetting the time each time it initializes

Thanks for the input though,
Lee

I'm having trouble using the DS3234 Rtc Chip, and after, reading all the posts, I see I'm not alone. Below is a sample output when I run the following Sparkfun example code. As you can see there is a repeatable pattern that doesn't make any sense every five lines, why I don't know. I have the interrupt connected but am not using it at this moment. I modified the code to read the DS3234 25 times and then wait forever. This is just a test mod and will be removed when it works. Any one have any ideas?

Any help will be greatly appreciated.

Hugh

#include <SPI.h>
const int cs=10; //chip select

void setup() {
Serial.begin(9600);
RTC_init();
//day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59)
SetTimeDate(11,12,13,14,15,16);
}

void loop() {
for(int zz = 0;zz < 25; zz++){
Serial.println(ReadTimeDate());
}
while(1){}
delay(1000);
}
//=====================================
int RTC_init(){
pinMode(cs,OUTPUT); // chip select
// start the SPI library:
SPI.begin();
SPI.setBitOrder(LSBFIRST);
SPI.setDataMode(SPI_MODE1); // both mode 1 & 3 should work
//set control register
digitalWrite(cs, LOW);
SPI.transfer(0x8E);
SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled
digitalWrite(cs, HIGH);
delay(10);
}
//=====================================
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*/10;*
int a= TimeDate_-b10;_
_
if(i==2){_
_
if (b==2)_
_
b=B00000010;_
_
else if (b==1)_
_
b=B00000001;_
_
} _
_ TimeDate= a+(b<<4);
digitalWrite(cs, LOW);
SPI.transfer(i+0x80);
SPI.transfer(TimeDate);
digitalWrite(cs, HIGH);
}
}
//=====================================
String ReadTimeDate(){
String temp;
int TimeDate [7]; //second,minute,hour,null,day,month,year
for(int i=0; i<=6;i++){
if(i==3)
i++;
digitalWrite(cs, LOW);
SPI.transfer(i+0x00);
unsigned int n = SPI.transfer(0x00);
digitalWrite(cs, HIGH);
int a=n & B00001111;
if(i==2){
int b=(n & B00110000)>>4; //24 hour mode*

* if(b==B00000010)
b=20;
else if(b==B00000001)
b=10;
TimeDate=a+b;
}
else if(i==4){
int b=(n & B00110000)>>4;
TimeDate=a+b10;

* }
else if(i==5){
int b=(n & B00010000)>>4;
TimeDate=a+b10;

* }
else if(i==6){
int b=(n & B11110000)>>4;
TimeDate=a+b10;

* }
else{
int b=(n & B01110000)>>4;
TimeDate=a+b10;

* }
}
temp.concat(TimeDate[4]);
temp.concat("/") ;
temp.concat(TimeDate[5]);
temp.concat("/") ;
temp.concat(TimeDate[6]);
temp.concat(" ") ;
temp.concat(TimeDate[2]);
temp.concat(":") ;
temp.concat(TimeDate[1]);
temp.concat(":") ;
temp.concat(TimeDate[0]);
return(temp);
}
=====================================================*

Generated output:
0/0/10 12:2:20
0/0/2 0:33:0
10/0/33 0:0:12
2/12/0 20:0:40
33/0/0 0:10:0
0/0/10 12:2:20
0/0/2 0:33:0
10/0/33 0:0:12
2/12/0 20:0:40
33/0/0 0:10:0
0/0/10 12:2:20
0/0/2 0:33:0
10/0/33 0:0:12
2/12/0 20:0:40
33/0/0 0:10:0
0/0/10 12:2:20
0/0/2 0:33:0
10/0/33 0:0:12
2/12/0 28:0:40
33/0/0 0:10:0
0/0/10 12:2:28
0/8/2 0:33:0
10/0/33 0:0:12
2/12/0 28:0:40
33/0/0 0:10:0_

Big Huey:

Try using Mode3 instead of Mode1. That was the only way I was able to get Sparkfun's example code to work. Your output looked similar to mine until I changed the SetDataMode command.

When I used that clock I used MSB first with MODE1:

SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);

Pete

NightTrain and el_supremo,

Thanks for your suggestions, however they did not solve the problem. I tried LSBFIRST, MSBFIRST, Mode1, and Mode3 in all combinations and the results are the same.

Bighuey

On a Mega 2560 v3, Wires correctly connected to 50-53, Mine was showing Dec 31 2165 23:60:60

After disconnecting wires to see if the Arduino was talking to the ds3234, I found that the combination of
SPI.setDataMode(SPI_MODE1) and Disconnecting the GND wire got it to work ok.

Hmm....