Friday, August 28, 2020

Reading Date/Time And Temperature From DS3232 Using PIC16F716

An Overview Of DS3232

DS3232 is an I2C protocol based RTC (real time clock) with a digital temperature inside. Its RAM store date/time, temperature and also a general purpose SRAM space.

Reading Date/Time And Temperature From DS3232 Using PIC16F716

A sample of program simulation


The device works at +3.3 V designed to fit any portable low power electronic applications. It's a 20-pin SMD device, requiring only a few external components. A very precise 32.768 kHz internal oscillator creates a timing for the device date/time. To keep the time working whenever it's power off, an external coin battery needed to connect to the Vbat pin of the IC.

DS3232 IC And Pins Diagram


Each pin has its function as lists below.

Pins description of DS3232 from device's datasheet

The I2C Interface

Inter-integrated circuit (I2C) is a two-wire serial communication developed by Phillip. It has been implementing by many manufacturers. 

For DS3232 this communication protocol could clocks up to 400 kHz from the master device. The device writing address is the same to DS1307. The writing address for this device is 0xD0 while the reading address is 0xD1.

Master MCU writes to DS3232

Master MCU reads from DS3232

This device also support continuous pointer reading mode, but I don't list them here due to a novice programming.

Address Map

Address map is a RAM space contains date/time, control, and SRAM space. Date/time and control registers ranges from 0x00 to 0x13, while the remanding 0x14 to 0xFF are the general SRAM registers.

Just like DS1307 the starting address of 0x00 is the second register.

Date/time registers are read/write, and continuous increase up on the clock pulses, addresses from 0x00 to 0x06. The control registers, set the device square wave out, alarm setting, temperature reading enable etc. The alarm settings have many options, I don't list them here.
The remanding SRAM is general-purpose to the user for temporary data storage.

Control Register

This register locates at 0x0E in RAM. It configures many operation of the device. 

Control Register
  • BIT 7 - Enable Oscillator: When device is powered on it's set to '0' to enable the oscillator. Setting this bit to '1', the device switch off from the oscillator.
  • BIT 6 - Battery-backed Square-wave Enable: If not necessary do not access to this bit.
  • BIT 5 - Convert Temperature: Setting this bit to '1' to enable temperature conversion. The temperature is 10-bit wide, and will be list next. The conversion takes at least 2 mS.
  • BIT 4:3 - Rate Select (RS2:1): They set the output frequency from INT/SQW pin.

Square-wave output frequency

  • BIT 2 - Interrupt Control: Setting this bit to 0 to enable the square wave output from INT/SQW pin.
  • BIT 1 - Alarm 2 Interrupt Enable: I don't use it here, please see the device's datasheet.
  • BIT 0 - Alarm 1 Interrupt Enable: I don't use it here, please see the device's datasheet.
This register also relate to control/status register.

Control/Status Register

This register locates at 0x0F. It contains some control and status bit.
  • BIT 7 - Oscillator Stop Flag: If it's '1' indicates that the oscillator is stop working.
  • BIT 6 - Battery-backed 32 kHz Output: If it's set to '1', it enable the 32 kHz output from the 32kHz pin when powered from the back up battery.
  • BIT 5:4 - Conversion Rate: These two bits determine the rate of temperature conversion (TCXO).
Conversion rate
  • BIT 3 - Enable 32 kHz Output: When this bit is set to '1' it enable the 32 kHz square wave output from the 32 kHz pin.
  • BIT 2 - BUSY: When this bit is read '1' indicates that the temperature conversion (TCXO) is not completed.
  • BIT 1 - Alarm 2 Flag: When it's set to '1' it indicates the time is matched in the alarm 2 register.
  • BIT 0 - Alarm 1 Flag: When it's set to '1' it indicates the time is matched in the alarm 1 register.

Temperature Registers

A digital thermometer is integrated inside the chip. Temperature data made of two bytes - the upper byte (0x11) and the lower byte(0x12).

At the upper byte the MSB bit 7 indicate the sign of temperature. When bit 7 is set to '1' it's at negative temperature environment. Then the upper temperature data must converter to 2'complement.

At the lower byte the two MSB bit indicate the fraction. It's 0.25 degree Celsius step.

SRAM

The SRAM is general purpose read/write RAM space for a user's temporary data storage. It ranges from 0x14 to 0xFF.

Interfacing And Programming.

With a software I2C library in CCS PICC, communicating with this device is pretty easy. Two SDA and SCL pins could be any pins within the I/O pin of the master MCU.

I selected RA0 and RA1 for SDA and SCL respectively.
Reading Date/Time And Temperature From DS3232 Using PIC16F716
Schematic Diagram

PIC16F716 clocks to 20 MHz, supplied at +5 V. DS3232 supplied at +3.3 V. Two resistor for data pins pull up to +3.3 V.

The LCD is 20x2 to fit all date/time and temperature data.

Today I just created a GitHub respiratory to store my working source codes.
CCS PICC source code is fed from my GitHub respiratory, lists below.


Click here to download the complete example.



No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)