the RTC of the LPC1224 problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

the RTC of the LPC1224 problem

2,495 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by leee on Sun Mar 24 20:25:20 MST 2013
我用了 LPC 里面的模板。
void RTC_Config(void)
{
    RTC_Init (0x04, 24);    // 这里如果选择PCLK作为时钟源的话 DR寄存器 不是每秒增加一次,还是要有计算公式
                            // 如果选择 1HZ DR寄存器又不走
                            // 书上的32KHZ 振荡器 是只外接的32.768KHZ晶振吗?

    RTC_SetLoad (0);              
RTC_SetMatch (60);                        
NVIC_EnableIRQ(RTC_IRQn);                            
RTC_Cmd (ENABLE);                       
  }





void RTC_Config(void)
{
    RTC_Init (0x04, 24);    // Here. Is DR the second register of the RTC? But it walked too fast,
// Not increase once per second.            
// And if I write "RTC_Init (0x00, 0);" select 1HZ clock . The DR of the RTC was not walk
    RTC_SetLoad (0);              
RTC_SetMatch (60);                        
NVIC_EnableIRQ(RTC_IRQn);                            
RTC_Cmd (ENABLE);                       
  }
Thank you very much!


标签 (1)
0 项奖励
回复
8 回复数

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Aug 06 16:45:30 MST 2013
In order the RTC to start working properly it needs a POR (power-on reset), but the debugger uses a soft reset, that's way your code stucks at that place. You should try:

1.- Do not use the debugger while working with the RTC (ugly, but it works) ... is this a silicon bug?  |(
2.- In your code use a led or something to know where your code is (remember that you are not using the debugger)
3.- Upload your code using the Flash Magic tool

After uploading your code issue a cold reset (power off and then power on)
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tschnagel on Fri Aug 02 04:13:24 MST 2013
I've connected a scope to pin 57 and check the crystal pins/caps and no oscillation.  I'm using the following parts
Crystal 815-ABS25-32.768KHZT
Caps (12pF) 80-C0805C120J3G
I've tried with a 100K resistor on RTCXOUT, and without a resistor and no luck.  :~
On the lpcxpresso board, they are using 5pF caps, and I have even tried that.

I'm using the same RTC code from the RTC_Blinky example, and the code hangs at

RTC_Init.....
  while(LPC_RTC->DR <3)
  {
     __NOP();
  }


The value of LPC_RTC->DR never changes.  Thats when I suspected the crystal was not osc. 
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Jul 31 16:32:44 MST 2013
I haven't seen the LPCXpresso for this chip, but my custom board is using two capacitors of 12pF each one, and no resistor, and the crystal is a one from Abracon. According to my experience any crystal from 12pF to 39pF would work.

Crystal: 815-AB26T-32.768KHZ
Capacitors: GRM1885C1H120JA01D

(All parts from www.mouser.com)


How do you know the RTC module is not oscillating? I tested the RTC with the example that comes with the bundle for the LPC1227 chip, RTC_Blinky. Is there continuity from the crystal's pins to the chip? Is the chip out of any low-power mode?

RTC_Blinky.c
#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "rtc.h"

extern void RTC_IRQHandler(void);/* Please see RTC.c */

int main(void)
{
/* Enable AHB clock to the GPIO domain. Enable all the clocks to all
GPIO ports. */
LPC_SYSCON->SYSAHBCLKCTRL |= 0xE0010000UL;

/* LED is P0_7 */
LPC_GPIO0->DIR |= 1<<12;
LPC_GPIO0->CLR |= 1<<12;

/* Initialize RTC */
if (RTC_Init(RTC_CLK_1KHZ, 0))
{
RTC_Load( 0 );
RTC_Match( RTC_MATCH );
}

/* Put M0 Core to sleep until and interrupt occurs */
while(1)
{
//__WFI(); // <-- it's hard to debug when in low-power
}

return 0 ;
}
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tschnagel on Tue Jul 30 03:54:15 MST 2013
Thanks for the quick reply.

I realized after I posted that the 1kHz clock can only be used with the 32khz crystal.  I have a 32khz crystal installed, but I have yet to get it working.  I used the same circuit as the lpcxpresso, but I get no oscillation  :( . 

What crystal/cap/resistor combination are you using?
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Sat Jul 27 16:39:29 MST 2013
I've succeded it using the 32KHz clock:


main.c
if (RTC_Init(RTC_CLK_1KHZ, 0))
{
RTC_Load( 0 );
RTC_Match( RTC_MATCH );
}


RTC.h
#define RTC_MATCH 100


(With those options my on-board led blinks at 100 ms (or 10 Hz) as expected. To get one second then change RTC_MATCH from 100 to 1000.)

As I said before, for this option to work you must have a 32KHz external clock, otherwise it won't work.
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Sat Jul 27 16:19:31 MST 2013
I've tried with the 1Khz output without success; however, I'm seeing that you are mixing concepts: if you use the PCLK clock then you can get any frequency you want, and you won't need the 32KHz external crystal. But in order to use the 1KHz clock then you need the external crystal (Fig 46, p278, UM10441). In order to use the 12MHz internal clock you should divide it by 12000000, shouldn't you?

if (RTC_Init(RTC_CLK_PCLK,12000000)) {
RTC_SetLoad(0);
RTC_SetMatch(1); // one second
RTC_Cmd(ENABLE);
        }


UPDATE: My 1 second interrupt is working as expected. This is (or was) the problem: once the RTC has been set, the RTC module needs a POR (power-on reset, e.g. power supply off and then on again) to be set with other values. A simply reset won't work and the code will stuck at the RTC_Init() function. And that is what exactly happens if I'm using the debugger, so my next attempt will be to try the 1 KHz clock but I'll upload the code serially with the Flash Magic tool.

ASAP I try all clock sources for the RTC I'll write a little tutorial for everyone that gets stuck atthis module as we've done.
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tschnagel on Fri Jul 26 07:59:53 MST 2013
I'm in the same situation.  I'm using LCP1227 at 12Mhz, using the LPC_CLK_PCLK and I can't get an accurate 1 hz count.  I have not had any success at getting the 1kHz RTC working.  Did you have any luck with 1KHz, if so, how do you have your clock's set?

Thanks
0 项奖励
回复

2,234 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Thu Jul 18 12:00:01 MST 2013
I'm having problems too with the RTC, but I can tell you a couple of things:

In order the RTC to work at 1 HZ you need an external 32KHz crystal.

If you're going to use any internal clock, then you need to divide the internal clock frecuency so you get the desire output frec.

Let's talk about code:

RTC_Init (0x00, 0);

In this case the second argument is not used, that's way its value is 0, but in this next escenario

RTC_Init (0x04, 24);

the second argument means the divider (or prescaler). If you've chosen, say, 1KHz internal clock, then the second argument should be 1000 in order to get a time interval of one second. BTW, the option 0x04 is not a valid one, so please use literal constants instead of magic numbers.


The NXP's sample project for the RTC bahaves erratically, that's the problem I'm facing right now.
0 项奖励
回复