Hi ,
I am using the following code with LPC2378 as Target, As on debugging this code , I should be able to read RTC_HOUR,RTC_MIN register. But as it reaches printf (bold) code lines. I am not able to do so. I am first time using RTC. Please Suggest how to read RTC and throw its value on UART.
As per my observation , there should be something which should be able to bring print control to UART 1 again after RTC initialization. And some variable which save the RTC register at a particular time instance. And Its an RTC, it should continuously show the time increment.
Please Suggest.
=============================================================================================== Code for RTC implementation ===============================================================================================
#include <LPC23xx.H> #include <stdio.h>
void Init_UART(void); void Init_RTC(void);
int main (void) { /* -------------Main----------------------------*/ Init_UART(); /* ----- Initializing UART-------------*/ Init_RTC(); /* ----- Initializing RTC-------------*/
printf("\n Real Time Clock "); printf("\n HOUR :%d",RTC_HOUR); printf("\n MIN :%d",RTC_MIN);
while(1) { /*-------------Infinite Loop-------*/ }
}
void Init_UART() {
/* UART 2 Enable */ PINSEL0 |= 0x40000000; /* Enable TxD1 in P0.15 */
PINSEL1 |= 0x00000001; /* Enable RxD1 in P0.16 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 78; /* 9600 Baud Rate @ 12.0 MHZ PCLK */
U1LCR = 0x03; /* DLAB = 0 */
printf("\n ***** UART Initialized ***** \n"); }
void Init_RTC(void) {
/*RTC Clock Intialization*/
PCONP = 0X00000200; /* RTC power enabled*/
RTC_PREINT = 0X0000016E; /* for Xtal @12MHZ */
RTC_PREFRAC = 0X0000001E;
RTC_CCR = 0X00000011;
RTC_ILR =0X1; /*clears the counter increment interrupt*/
RTC_HOUR=12;
RTC_MIN=45;
RTC_SEC=59;
RTC_DOM=21;
RTC_MONTH=12;
RTC_YEAR=2011;
printf("\n HOUR :%d",RTC_HOUR); printf("\n MIN :%d",RTC_MIN); }
Best Regards,
Vinay. Kumar
You probably showed the same care when writing your code, as you showed when posting it.
Why did you chose to not read the instructions and use the "pre" tag around the code?
Another thing - be careful about writing full values to registers.
How many bits do you think you affect with this write? What about power to your UART? Didn't you notice in the user manual that PCONP on reset have a number of bits set? Did you really make an explicit decision about every of these bits before you decided to zero them with the above assign?
Spend some more time working through your code. You even have access to a debugger - check that every line of your code does exactly what you think it does. Be a bit careful.
Thanks for your suggestion. I will definitely try to look over everything from Next Time. As I am a beginner to it. So Please do forgive for silly mistake.
BEST REGARDS
Hi Per Westermark,
Now I am able to get output on UART1
As Output is like this. To make this I created one if else and(++) based conditions.
If I am not USING this if else then RTC stops after displaying printf output.
Not able to see the Counter happening which is happening in RTC without printf.
I want to set RTC COUNTER and Output on every counter increment in sec,min,hour and Day,month and year.
Just give me idea, I will try to implement it my own.
***** UART Initialized *****
Digital Date and Time Clock DAY::MONTH::YEAR 21 / 12 / 2011
------------------------------------------
****** HOUR::MIN::SEC********** 12::46::0 ****** HOUR::MIN::SEC********** 12::46::1 ****** HOUR::MIN::SEC********** 12::46::2 ****** HOUR::MIN::SEC********** 12::46::3 ****** HOUR::MIN::SEC********** 12::46::4 ****** HOUR::MIN::SEC********** 12::46::5 ****** HOUR::MIN::SEC********** 12::46::6 ****** HOUR::MIN::SEC********** 12::46::7 ****** HOUR::MIN::SEC********** 12::46::8 ****** HOUR::MIN::SEC********** 12::46::9 ****** HOUR::MIN::SEC********** 12::46::10 ****** HOUR::MIN::SEC********** 12::46::11 ---------------------------------------------
Best Regards