In this tutorial, we will see how we can interface DS3231 RTC module to ARIES V2 board. Real Time Clock (RTC) is an electronic device which is used to provide precise time and date in various applications like GPS, Servers, Data loggers etc. It is powered by an on board lithium battery, which makes RTC work even when the power is off.

DS3231 RTC

The DS3231 RTC module is low cost and communicates over I2C interface having a supply voltage range from 2.3V to 5.5V . It has an in built crystal oscillator and temperature sensor which makes the IC more compact. A secondary EEPROM IC of 32 KB size is also provided with this module. To provide uninterrupted power supply, there is a provision to provide battery also.

Circuit Diagram

Connect SDA and SCL pins of DS3231 RTC module to SDA1 and SCL1 pins of ARIES V2 board. Then connect VCC and GND of the RTC module to +3.3V and GND respectively of the ARIES board. (Refer DS3231 datasheet).

Now, for powering up the ARIES v2 board via USB port of a Laptop/Desktop/PC and burning the code into the ARIES v2 board, we have to use a micro USB type B to USB type A cable. The cable should be connected to UART0 port of the ARIES v2 board, and the Laptop/Desktop/PC should be preinstalled with VEGA SDK and Toolchain.

DS3231ARIES v2 Board
VCC3.3V
GNDGND
SCLSCL1
SDASDA1

Procedure

After setting up the tool chain and SDK path environments, set the date and time by editing the file in set_RTC_DS3231. You can make set date, month, year and time as shown in the following sample code.

/**
 @fn main
 
 @param[in] No input parameters.
 @param[Out] No ouput parameter.
 @return Void function.

 */
void main() {
	//UC rxd_data[7];
	printf(" I2C ds3231 RTC\n\r");
	i2c_configure(I2C_1, SYS_FREQ, I2C_FREQ); //System clock =40MHz and I2C clock =100 kHz
	//i2c_initialize(0);

	gRTCtime.sec = 00; // Edit here to set seconds
	gRTCtime.min = 20; // Edit here to set the minutes
	gRTCtime.hour = 4; // Edit here to set the hour
	gRTCtime.mday = 7; //Edit here to set the day
	gRTCtime.mon = 6; //Edit here to set the month
	gRTCtime.year = 2022; // Edit here to set the year
	gRTCtime.wday = 3; //Edit here to set the day of the week
	gRTCtime.year_s = 20;

	printf(" set value : %02d-%02d-%02d, %02d:%02d:%02d \n\r", gRTCtime.mday, gRTCtime.mon,
				gRTCtime.year_s, gRTCtime.hour, gRTCtime.min, gRTCtime.sec);
	i2c_set_rtc_DS3231(I2C_1, DS3231_TIME_CAL_ADDR, DS3231_I2C_ADDR_WR);
	printf(" write completed\n\r");
	while (1) {
		i2c_get_rtc_DS3231(I2C_1, DS3231_I2C_ADDR_WR,
		DS3231_I2C_ADDR_RD, DS3231_TIME_CAL_ADDR);

		printf("\r %02x-%02x-%02x, %02x:%02x:%02x, ", gRTCtime.mday, gRTCtime.mon,
				gRTCtime.year_s, gRTCtime.hour, gRTCtime.min, gRTCtime.sec);
		switch (gRTCtime.wday) {
		case 1:
			printf("Sunday   ");
			break;
		case 2:
			printf("Monday   ");
			break;
		case 3:
			printf("Tuesday  ");
			break;
		case 4:
			printf("Wednesday");
			break;
		case 5:
			printf("Thursday ");
			break;
		case 6:
			printf("Friday   ");
			break;
		case 7:
			printf("Saturday ");
			break;

		}
		udelay(2000);
	}

	//printf("success \n\r");
	//while (1)
	//;
}

Clean the executable by using the make clean command.

cd examples/i2c/rtc_ds3231/set_RTC_DS3231
make clean

Build the edited example program for setting DS3231 RTC by using make command

make 

Before transfering the built program to board, ensure that you have connected the UART0 connector of the board to the PC.

Open a new terminal, execute the following command

sudo minicom aries

Now you can see the minicom terminal opened and the board UART terminal is ready

Use CTRL+A S to enter file sending menu and select xmodem by pressing Enter.

In the next window, with space bar select the i2c_rtc.bin file to be transferred, by pressing Enter, transfer process starts.

Wait until the process is completed. The screen should display how much data has been transferred.

After completing transfer, the Program will start to execute.

The set RTC date and time will be displayed on minicom UART terminal.

Note: After setting the date and time in RTC, you can compile and run examples/i2c/rtc_ds3231/read_RTC_DS3231 to read back and display the date, time and day of the week on minicom(if using the same RTC).

Leave a Reply

Your email address will not be published. Required fields are marked *