Wednesday, September 7, 2016

Interfacing RTC PCF8523 with Cortex-M3

Click Here to read Using Internal ADC of Cortex-M3.
In this tutorial, I2C of LPC1343 is used to Read and Write data to a Real Time Clock Calendar Integrated Chip, PCF8523 which works on I2C Protocol and has 8-bit address of 0xD0. In this tutorial first of all time and date is written to the RTC and then after that time and date is continuously read from RTC and displayed on Semi-hosting Window.
Click Here to know more about Semi-Hosting.

Schematic Diagram:
Schematic Diagram
As clearly seen in the schematic diagram above, PCF8523 is connected to I2C's SCL (Clock) and SDA (Data) pins of LPC1343, CooCox Community provide very good I2C library for LPC13XX, but we have our simpler library for I2C protocol, present in i2c folder and for PCF8523 library in driver folder. 
The I2C Library has special debug feature controlled with the help of macros I2C_DEBUG and SEMIHOSTING.
 

The code is as follow:
 #include "config.h"  
 #include "lpc13xx_gpio.h"  
 #include "pcf8523.h"  
 #ifdef SEMIHOSTING  
 #include "semihosting.h"  
 #endif  
 int main(void)  
 {  
  u8_t second, minute, hour;  
  u8_t date, month, year;  
  InitializeSystem();  
  // Initialize RTC  
  PCF8523_Init();  
  // Set Time and Date  
  PCF8523_SetTimeDate(0x01, 0x13, 0x00, 0x05, 0x04, 0x15);  
  while(1)  
  {  
   // Read Seconds, Minutes, Hours, Date, Month and Year from RTC  
   second = PCF8523_Read(SECONDS);  
   minute = PCF8523_Read(MINUTES);  
   hour  = PCF8523_Read(HOURS);  
   date  = PCF8523_Read(DAYS);  
   month = PCF8523_Read(MONTHS);  
   year  = PCF8523_Read(YEARS);  
 #ifdef SEMIHOSTING  
   printf("Time : %x:%x:%x\n", hour, minute, second);  
   printf("Date : %x/%x/%x\n", date, month, year);  
 #endif  
  }  
 }

Have a look at the following video for project demonstration.



Click Here to Download the Complete Source Code.

No comments:

Post a Comment