problem with RTC in lpx1769

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem with RTC in lpx1769

464 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toniojesusde on Wed Jan 19 05:02:03 MST 2011
Hi,

I am trying to use the RTC (Real time clock) in the LPC1769 xpresso board.
So i develop a little piece of code to try it out:

//RTC initialization:
[SIZE=2][LEFT]LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CCR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= !0x01|0x02;[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//enable RTC clock[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CCR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= ~0x02;
LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DOY[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=0;
LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HOUR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=0;
LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIN[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=0;[/LEFT]
LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SEC[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=0;[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]//showing the time:[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2][SIZE=2][LEFT]debug_printf([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"RTC : %2.2d:%2.2d:%2.2d:%2.2d\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DOY[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HOUR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIN[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/LEFT]
LPC_RTC->[U]SEC[/U]);


When I do this, i get strage numbers in the console. DOY, HOUR, MIN and SEC , all of them increment each second.

So I end up reading:
[SIZE=2][LEFT]RTC : 0: 0: 0: 0
RTC : 1: 1: 1: 1
RTC : 2: 2: 2: 2
RTC : 3: 3: 3: 3[/LEFT]
...
I have checked all the registers associated to the RTC but all of them seem to be properly configured. Also, I looked at the registers of sec, min, hour, ... in the RTC peripheral registers, and they show the same erratic behaviour. What can be wrong? Some help would be appreciated.

Thanks a lot,

Antonio
[/SIZE]

[/SIZE][/SIZE]
0 Kudos
7 Replies

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toniojesusde on Wed Jan 19 08:00:36 MST 2011
Thanks a lot! that solved the problem! I will make sure to dig into the whole code and register definition next time.
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jan 19 07:28:37 MST 2011
Especially Bit 3 of CCR :)
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Jan 19 07:14:10 MST 2011
The problem lies in the very first line of your RTC init code - it sets almost all bits of CCR to ones, which probably turns on some factory testing mode.
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jan 19 06:23:34 MST 2011
Try to write correct date / time to RTC:

[LEFT]LPC_RTC->DOM = 19;
LPC_RTC->MONTH = 1;
LPC_RTC->YEAR = 2011;[/LEFT]
LPC_RTC->HOUR = 14;
[LEFT]LPC_RTC->MIN = 19;[/LEFT]
LPC_RTC->SEC = 1;


Read your RTC data via debugger. Are they also wrong?

Use a correct RTC_init like
void RTC_init(void) //init RTC
[LEFT]{
PCONP |= (1<<9); //power on RTC
if(PWRCTRL & (1<<4)) //stopped? 
{
PWRCTRL |= (1<<4); //clear bit by writing 1[/LEFT]
}
CCR =0; //stop RTC
AMR =0; //no alarm
[LEFT]CIIR =0;  //no interrupt[/LEFT]
CCR |= CCR_CLKEN;
}



[LEFT]Post your actual code again.[/LEFT]
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by toniojesusde on Wed Jan 19 06:07:53 MST 2011
[SIZE=2][LEFT]I tried running that code, still got the werid results, have a look:

Loop number : 0
02.04.2646 02:02:02
Loop number : 1
03.05.2647 03:03:03
Loop number : 2
05.07.2649 05:05:05
Loop number : 3
07.09.2651 07:07:07
Loop number : 4
09.11.2653 09:09:09
Loop number : 5
10.28.2654 10:10:10
Loop number : 6
12.02.2656 12:12:12
Loop number : 7
14.04.2658 14:14:14
Loop number : 8
16.06.2660 16:16:16
Loop number : 9[/LEFT]
17.07.2661 17:17:17
[/SIZE]
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jan 19 05:49:11 MST 2011

Quote: toniojesusde

...

[SIZE=2][SIZE=2]debug_printf([/SIZE]
[LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"RTC : %2.2d:%2.2d:%2.2d:%2.2d\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DOY[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2]LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HOUR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2]LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIN[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2]LPC_RTC->[U]SEC[/U]);[/SIZE][/LEFT]
[/SIZE]



[LEFT]Try something like:[/LEFT]

[B][SIZE=2][COLOR=#642880][SIZE=2][COLOR=#642880]printf[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"%02d.%02d.%04d %02d:%02d:%02d\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DOM[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MONTH[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]YEAR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HOUR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIN[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],LPC_RTC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SEC[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]


RTC isn't very problematic at all. It's running or it's not running. As you described values are changing every second, your RTC is running and you should be able to read RTC values direct via debugger in Peripherals View.

Your printf format string (%2.2d) is trying to output an integer with 2 decimal places, so that's wrong.

To output a fixed-length field with '0' instead of space, use '%02d'.
0 Kudos

424 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Wed Jan 19 05:15:54 MST 2011
Googling "RTC site:knowledgebase.nxp.com" shows up a couple of previous forum threads (with example code) on the LPC17 RTC which might help you get up and running...

http://knowledgebase.nxp.com/showthread.php?t=718
http://knowledgebase.nxp.com/showthread.php?t=682

HTH!
0 Kudos