011 - Brickcell RTC DS3231 | MakeCode Microbit

Introduction

The DS3231 is a popular real-time-clock (RTC) integrated circuit (IC) manufactured by Maxim Integrated. An RTC is a device that keeps track of time even when the main power source to a system, such as a microcontroller or a computer, is turned off or unavailable. The DS3231 is commonly used in a variety of electronic applications to provide accurate timekeeping and timestamp functionality.

High Accuracy

THe DS3231 is known for its excellent timekeeping accuracy, often within a few seconds per month, making it suitable for applications where precise timekeeping is required.

Temperature Compensation

The DS3231 incorporates a temperature-compensated crystal oscillator (TCXO) that helps maintain accurate timekeeping over a wide temperature range.

Battery Backup

I has a built-in backup power supply circuit that allows it to continue running on a small coin cell battery (typically CR2032) when th4e primary power source is disconnected. This ensures that the RTC continues to keep time even during power outages.

I2C Interface

The DS3231 communicates with a host microcontroller or other devices through the I2C (Inter-Integrated Circuit) interface, making it easy to interface with various microcontrollers.

Alarm Functions

The DS3231 can be configured to trigger alarms at specific times or dates, making it useful for applications that require scheduled events.

32 KHz Output

It provides a 32 kHz square wave output that can be used as clock signal for other devices.

Programmable Square-Wave Output

It can generate square wave signals with a selectable frequency (1Hz, 1.024kHz, 4.096kHz, or 8,192kHz) for various timing applications.

Low Power Consumption

It is designed to consume very low jpower, making it suitable for battery-powered devices.

Hardware Instruction

Let's explore how to connect the DS3231 RTC to a micro:bit microcontroller and utilize MakeCode for programming.

  1. Connect the DS3231 RTC GND pin to microbit GND pin.
  2. Connect the DS3231 RTC VCC pin to microbit VCC pin.
  3. Connect the DS3231 RTC serial data pin (SDA) to microbit pin 20.
  4. Connect the DS3231 RTC serial clock pin (SCL) to microbit pin 19.

Software Instruction

Now, let's start into programming the micro:bit to utilize the DS3231 real-time-clock module.

  1. Login to https://makecode.microbit.org/ using your Microsoft account.
  2. Create a new project by clicking the "New Project" button. You may name it anything you want, I suggest to name it with descriptive name such as "rtc-ds3231-test".
  3. Click the "Extensions" block just under the "Math" block.
  4. Type https://github.com/gbantique/brickcell-rtc-ds3231/ on the search bar.
  5. Select the "brickcell-rtc-ds3231" from the search results. The "rtc ds3231" block should appear under the "Brickcell" block.
  6. Copy the code provided below.
1serial.setBaudRate(BaudRate.BaudRate115200)
2Brickcell.setDate(2, 10, 10, 2023)
3Brickcell.setTime(8, 6, 0)
4basic.forever(function () {
5    serial.writeLine(Brickcell.getDate())
6    serial.writeLine(Brickcell.getTime())
7    serial.writeLine("")
8    basic.pause(2000)
9})
  1. Open a Serial Monitor such as Termite terminal app https://www.compuphase.com/software_termite.htm/. Set the baud rate to 115200 bps.

Or you make a copy of my created project in your MakeCode workspace.

https://makecode.microbit.org/S07528-47249-67053-50399/

Expected Result

If you carefully follow the provided instruction above, you should be able to view the date and time on the serial terminal every 2000 milliseconds.



Posts in this series



No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.