How to use the DS3234 RTC module with arduino UNO?

eg. Breakout Boards, Cables ,Cellular,Sensors,Components ,LCDs+LEDS,Programmers, DMX512,Ethernet,Security and Spy Camera,Storage,Video,Tracking,Tools

Moderators: vaico, sunzhanshan

How to use the DS3234 RTC module with arduino UNO?

Postby CindyKuai » 2012-11-07 21:23

Image
http://www.soliddepot.com/index.php?main_page=product_info&cPath=46_56&products_id=23

Use SPI interface to control the DS3234 RTC module. Connection:
DS3234 module ------ arduino UNO
VCC ------ 5V
GND ------- GND
SCLK1 or SCLK2 ------ D13
DOUT ------ D12
DIN ------ D11
CS ------ D8

code:
Code: Select all
#include <SPI.h>
const int  cs=8; //chip select
int date;
int temp1[17];
int temp2[6];
void setup() {
  Serial.begin(9600);
  RTC_init();
  //SetTimeDate(11,12,13,14,15,16);
}

void loop() {
  Serial.println(ReadTimeDate());
  delay(1000);
  Uart_timedata();
}
int Uart_timedata()
{
    if (Serial.available() > 0) //
    {
      for(int i=0; i<17;i++)
      {
        date = Serial.read(); //
        switch(date)
        {
          case 48:
          temp1[i] = 0;
          break;
          case 49:
          temp1[i] = 1;
          break;
          case 50:
          temp1[i] = 2;
          break;
          case 51:
          temp1[i] = 3;
          break;
          case 52:
          temp1[i] = 4;
          break;
          case 53:
          temp1[i] = 5;
          break;
          case 54:
          temp1[i] = 6;
          break;
          case 55:
          temp1[i] = 7;
          break;
          case 56:
          temp1[i] = 8;
          break;
          case 57:
          temp1[i] = 9;
          break;
        }
    }
          for(int i=0; i<6;i++)
         {
           temp2[i] = temp1[3*i]*10 + temp1[(3*i)+1];
         }   
    //day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59)
    SetTimeDate(temp2[0],temp2[1],temp2[2],temp2[3],temp2[4],temp2[5]);
  }
}
//=====================================
int RTC_init(){
     pinMode(cs,OUTPUT); // chip select
     // start the SPI library:
     SPI.begin();
     SPI.setBitOrder(MSBFIRST);
     SPI.setDataMode(SPI_MODE3); // 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[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);
  }
}
//=====================================
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[i]=a+b;
      }
      else if(i==4){
         int b=(n & B00110000)>>4;
         TimeDate[i]=a+b*10;
      }
      else if(i==5){
         int b=(n & B00010000)>>4;
         TimeDate[i]=a+b*10;
      }
      else if(i==6){
         int b=(n & B11110000)>>4;
         TimeDate[i]=a+b*10;
      }
      else{   
         int b=(n & B01110000)>>4;
         TimeDate[i]=a+b*10;   
         }
   }
   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);
}


Open the Serial Monitor:
Image

You can set the time again, data month year hour minute second (note: intermediate for a space):
Image
Last edited by CindyKuai on 2013-04-10 19:58, edited 1 time in total.
CindyKuai
 
Posts: 17
Joined: 2011-10-06 4:38

How to use the DS1302 RTC module with arduino mini?

Postby CindyKuai » 2012-11-07 23:15

Image
http://www.soliddepot.com/index.php?main_page=product_info&cPath=46_56&products_id=220

Image

Connection:
CE(DS1302 pin5) -> Arduino D5
IO(DS1302 pin6) -> Arduino D6
SCLK(DS1302 pin7) -> Arduino D7
Vcc2(DS1302 pin1) -> Arduino +5v
GND(DS1302 pin4) -> Arduino GND
Image

Then unzip the DS1302 code library file "DS1302 1.0. zip" to the libraries of arduino 1.0.
DS1302 1.0.zip
ds1302 code library
(6.59 KiB) Downloaded 1252 times

Open "DS1302_Example", download to the arduino, open the Serial Monitor,
Image
CindyKuai
 
Posts: 17
Joined: 2011-10-06 4:38

How to play the DS1307 RTC module with arduino UNO?

Postby CindyKuai » 2012-11-14 23:55

This is a kind of RTC module. A DS18B20 temperature sensor and a memory chip are also integrated.

Image
Image
You can buy from here: http://www.soliddepot.com/index.php?main_page=product_info&cPath=46_56&products_id=222

The circuit connection:
Image

Now we explain from three aspects respectively.
1. DS1307 RTC chip function
2. DS18B20 temperature sensor
3.AT24C32A EEPROM read and write

1) DS1307 RTC chip function
Copy the code below to arduino-0022 libraries, then open "DS1307" example.
DS1307.rar
DS1307 code library - arduino 0022
(2.59 KiB) Downloaded 2147 times

Then you can see:
Image
CindyKuai
 
Posts: 17
Joined: 2011-10-06 4:38


Return to Other products

Who is online

Users browsing this forum: No registered users and 1 guest

cron