Overview
The DS3234 is a low-cost, extremely accurate SPI bus real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The DS3234 incorporates a precision, temperature-compensated voltage reference and comparator circuit to monitor VCC. When VCC drops below the power-fail voltage (VPF), the device asserts the RST output and also disables read and write access to the part when VCC drops below both VPF and VBAT. The RST pin is monitored as a push button input for generating a µP reset. The device switches to the backup supply input and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line. The DS3234 is available in commercial and industrial temperature ranges, and is offered in an industry-standard 300-mil, 20-pin SO package.
It does not have a DIP version due to larger footprint. But a ready to use module is widely available at very low cost.

Its internal time keeping and general purpose registers are similar to the DS1307 and almost identical to DS3232 (TWI version). However its SPI interface yield a higher speed data communication than TWI.
| DS3234 Pin Configuration and Description |
Its timing data is very precise due its internal 32.678KHz crystal oscillator with programmable capacitors array.
| Block Diagram |
The DS3234 provides 256 bytes of general-purpose battery-backed read/write memory. The SRAM can be written or read whenever VCC is above either VPF or VBAT.
| Address Map for DS3234 Timekeeping Registers and SRAM |
This SPI chip doesn't have a device address. It just uses a Chip Select (CS) pin that is active low. Its R/W MSB bit of the internal SRAM address identifies between device write and read( '0' for read and '1' for write).
| DS3234 Single-Byte Write and Read Sequence |
However for a high speed multiple write or read bytes we can use its SPI mutliple-Byte Burst Transfer.
| SPI Multiple-Byte Burst Transfer |
It is very common for data reading from this chip.
ATMega644P and DS3234 Interfacing
Programming and interfacing with this chip is very easy using a simple 8-bit MCU dedicated SPI communication module. Even a low-end 8-bit micro-controller that doesn't have an SPI communication interface the programmer can emulate an SPI communication protocol to interact with this RTC chip.
| Typical Operating Circuit |
Commonly a master MCU uses only four wire SPI to make a bi-directional communication interface with this RTC chip.
| Proteus Simulation |
| Virtual DSO Waveform |
In this example the ATMega644P read the time and date data from the SRAM of DS3234. A character LCD show time and date on the display. Serial data inputs to MISO pin are sample at the trailing edge of each clock cycles of SCK pin to correct the data reception that is CPOL=0 and CPHA=1.
C Source Code "main.c":
- /*
- * 12-spi_ds3234_1602.c
- *
- * Created: 2/16/2026 10:52:32 PM
- * Author : Admin
- */
- #include <stdio.h>
- #include <avr/io.h>
- #include <util/delay.h>
- #define F_CPU 16000000UL
- #define DDR_SPI DDRB
- #define PRT_SPI PORTB
- #define DD_MOSI 5
- #define DD_MISO 6
- #define DD_SCK 7
- #define DD_SS 4
- void SPI_MasterInit(void)
- {
- /* Set MOSI and SCK output, all others input */
- DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);
- /* Enable SPI, Master, set clock rate fck/16
- data is sample at the falling edge of SCK*/
- SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<CPHA);
- }
- void SPI_MasterTransmit(char cData)
- {
- /* Start transmission */
- SPDR = cData;
- /* Wait for transmission complete */
- while(!(SPSR & (1<<SPIF)))
- ;
- }
- void SPI_SlaveInit(void)
- {
- /* Set MISO output, all others input */
- DDR_SPI = (1<<DD_MISO);
- /* Enable SPI */
- SPCR = (1<<SPE);
- }
- char SPI_SlaveReceive(void)
- {
- /* Wait for reception complete */
- while(!(SPSR & (1<<SPIF)))
- ;
- /* Return Data Register */
- return SPDR;
- }
- int main(void)
- {
- /* Replace with your application code */
- SPI_MasterInit();
- PRT_SPI|=(1<<DD_SS); //Set CS Pin High
-
- lcd_init();
- lcd_text("ATMega644P AVR");
- lcd_xy(1,2);
- lcd_text("DS3234 SPI RTC");
- _delay_ms(5000);
- lcd_command(0x0C);
- unsigned char data[7],msg[16];
- while (1)
- {
- PRT_SPI&=~(1<<DD_SS);
- SPI_MasterTransmit(0x00);
- for (char i=0;i<7;i++)
- {
- SPI_MasterTransmit(0x00);
- data[i]=SPDR;
- }
- PRT_SPI|=(1<<DD_SS);
- sprintf(msg,"Date: 20%02X/%02X/%02X",data[6],data[5],data[4]);
- lcd_xy(1,1);
- lcd_text(msg);
- sprintf(msg,"Time: %02X:%02X:%02X",data[2],data[1],data[0]);
- lcd_xy(1,2);
- lcd_text(msg);
- _delay_ms(100);
- }
- }
I can not buy this chip at local store. So I only tested this SPI RTC chip using a software simulator.
No comments:
Post a Comment