EmbeddedRelated.com
Forums

LPC 2368 - RTC interrupt each seconde big problems

Started by rene February 15, 2011
hi
In the past, I make the same code(approx) with LPC2106 and all work fine !

I have a problem with the rtc with lpc2368. I work with IAR 4.2
I want have one and only one interrupt each seconds
here is my code:

RTC_Init (void){
AMR = 0;
CIIR = 1;
CCR = 0;

PREINT = ( PREINT & ~PREINT_RTC_MASK ) | PREINT_RTC;
PREFRAC = ( PREFRAC & ~PREFRAC_RTC_MASK ) | PREFRAC_RTC;
if ( install_irq( 13, (void *)vRtcISR , 13 ) == pdFALSE )
{
FIO2SET = 0x00000020; // just a led for debug
}

...
...
}

I found this code on the NET
/********************************************************************
** Function name: install_irq
**
** Descriptions: Install interrupt handler
** parameters: Interrupt number, interrupt handler address,
** interrupt priority
** Returned value: true or false, return false if IntNum is out of range
**
*********************************************************************/
DWORD install_irq( DWORD IntNumber, void *HandlerAddr, DWORD Priority )
{
DWORD *vect_addr;
DWORD *vect_cntl;

VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */
if ( IntNumber >= VIC_SIZE )
{
return ( FALSE );
}
else
{
/* find first un-assigned VIC address for the handler */
vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber*4);
vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber*4);
*vect_addr = (DWORD)HandlerAddr; /* set interrupt vector */
*vect_cntl = Priority;
VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
return( TRUE );
}
}

and the last piece is the IRQ

//------------
// Fonction: vRtcISR
// Desc : code de traitement de l'interruption
//------------
__irq __arm void vRtcISR( void )
{

RTC_ILR |= ILR_RTCCIF;
g_ILR = ILR;

RTC_INT_CallBack();
/* Clear the ISR in the VIC. */
VICVectAddr = 0;
FIO2SET = 0x00000080; // just another led for debug

portEND_SWITCHING_ISR( pdTRUE );

}

the function : RTC_INT_CallBack(); just increment some counters
The problem was: I have environ 35 to 40 call to RTC_INT_CallBack() at
every seconds.

I have interrupt if I put register CIIR = 0 !

Something fire the interrupt many many time. But I can't find who
Help me please ( Or I kill (and eat) a puppy) :-))
I have lost 4 hours with google and many PDF manual before write this ! ( and a big lot of [ test, compil, flash and run ]on my card)

some line of my dump :
t is my counter 19 is minute 41 is seconds (read from RTC)
you can see than t= jump 35 to 69 for the fist seconds
in place of 0 to 1, then 2 then 3 etc

Console wait
t5 19 41 g_ILR000000
ti 19 42 g_ILR000000
t3 19 43 g_ILR000000
t8 19 44 g_ILR000000
t3 19 46 g_ILR000000
t 7 19 47 g_ILR000000
t$2 19 48 g_ILR000000
t'6 19 49 g_ILR000000
t10 19 50 g_ILR000000
t45 19 51 g_ILR000000
t79 19 52 g_ILR000000

thank for all

An Engineer's Guide to the LPC2100 Series

Hi:

You need to add the following instruction in the RTC_Init() code:

CISS = 0;

This disables the Sub-second interrupts.

Regards,

Alex

--- In l..., "rene" wrote:
>
> hi
> In the past, I make the same code(approx) with LPC2106 and all work fine !
>
> I have a problem with the rtc with lpc2368. I work with IAR 4.2
> I want have one and only one interrupt each seconds
> here is my code:
>
> RTC_Init (void){
> AMR = 0;
> CIIR = 1;
> CCR = 0;
>
> PREINT = ( PREINT & ~PREINT_RTC_MASK ) | PREINT_RTC;
> PREFRAC = ( PREFRAC & ~PREFRAC_RTC_MASK ) | PREFRAC_RTC;
> if ( install_irq( 13, (void *)vRtcISR , 13 ) == pdFALSE )
> {
> FIO2SET = 0x00000020; // just a led for debug
> }
>
> ...
> ...
> }
>
> I found this code on the NET
> /********************************************************************
> ** Function name: install_irq
> **
> ** Descriptions: Install interrupt handler
> ** parameters: Interrupt number, interrupt handler address,
> ** interrupt priority
> ** Returned value: true or false, return false if IntNum is out of range
> **
> *********************************************************************/
> DWORD install_irq( DWORD IntNumber, void *HandlerAddr, DWORD Priority )
> {
> DWORD *vect_addr;
> DWORD *vect_cntl;
>
> VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */
> if ( IntNumber >= VIC_SIZE )
> {
> return ( FALSE );
> }
> else
> {
> /* find first un-assigned VIC address for the handler */
> vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber*4);
> vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber*4);
> *vect_addr = (DWORD)HandlerAddr; /* set interrupt vector */
> *vect_cntl = Priority;
> VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
> return( TRUE );
> }
> }
>
> and the last piece is the IRQ
>
> //------------
> // Fonction: vRtcISR
> // Desc : code de traitement de l'interruption
> //------------
> __irq __arm void vRtcISR( void )
> {
>
> RTC_ILR |= ILR_RTCCIF;
> g_ILR = ILR;
>
> RTC_INT_CallBack();
> /* Clear the ISR in the VIC. */
> VICVectAddr = 0;
> FIO2SET = 0x00000080; // just another led for debug
>
> portEND_SWITCHING_ISR( pdTRUE );
>
> }
>
> the function : RTC_INT_CallBack(); just increment some counters
> The problem was: I have environ 35 to 40 call to RTC_INT_CallBack() at
> every seconds.
>
> I have interrupt if I put register CIIR = 0 !
>
> Something fire the interrupt many many time. But I can't find who
> Help me please ( Or I kill (and eat) a puppy) :-))
> I have lost 4 hours with google and many PDF manual before write this ! ( and a big lot of [ test, compil, flash and run ]on my card)
>
> some line of my dump :
> t is my counter 19 is minute 41 is seconds (read from RTC)
> you can see than t= jump 35 to 69 for the fist seconds
> in place of 0 to 1, then 2 then 3 etc
>
> Console wait
> t5 19 41 g_ILR000000
> ti 19 42 g_ILR000000
> t3 19 43 g_ILR000000
> t8 19 44 g_ILR000000
> t3 19 46 g_ILR000000
> t 7 19 47 g_ILR000000
> t$2 19 48 g_ILR000000
> t'6 19 49 g_ILR000000
> t10 19 50 g_ILR000000
> t45 19 51 g_ILR000000
> t79 19 52 g_ILR000000
>
> thank for all
>

hi, and thank A LOT, it's work fine when I set CISS = 0;

I have not read with care this part of doc
"Counter Increment Select Mask Register (CISS - 0xE002 4040"

this f%!?*g register is not set to zero at reset.

SubSecEna Subsecond interrupt enable. reset state : NC
0 The sub-second interrupt is disabled.
1 The sub-second interrupt is enabled

Bye and "merci beaucoup"

An old frog near Paris. :-)



--- In l..., "alexander_ribero" wrote:
>
> Hi:
>
> You need to add the following instruction in the RTC_Init() code:
>
> CISS = 0;
>
> This disables the Sub-second interrupts.
>
> Regards,
>
> Alex
>
>
> --- In l..., "rene" wrote:
> >
> > hi
> > In the past, I make the same code(approx) with LPC2106 and all work fine !
> >
> > I have a problem with the rtc with lpc2368. I work with IAR 4.2
> > I want have one and only one interrupt each seconds
> > here is my code:
> >
> > RTC_Init (void){
> > AMR = 0;
> > CIIR = 1;
> > CCR = 0;
> >
> > PREINT = ( PREINT & ~PREINT_RTC_MASK ) | PREINT_RTC;
> > PREFRAC = ( PREFRAC & ~PREFRAC_RTC_MASK ) | PREFRAC_RTC;
> >
> >
> > if ( install_irq( 13, (void *)vRtcISR , 13 ) == pdFALSE )
> > {
> > FIO2SET = 0x00000020; // just a led for debug
> > }
> >
> > ...
> > ...
> > }
> >
> > I found this code on the NET
> > /********************************************************************
> > ** Function name: install_irq
> > **
> > ** Descriptions: Install interrupt handler
> > ** parameters: Interrupt number, interrupt handler address,
> > ** interrupt priority
> > ** Returned value: true or false, return false if IntNum is out of range
> > **
> > *********************************************************************/
> > DWORD install_irq( DWORD IntNumber, void *HandlerAddr, DWORD Priority )
> > {
> > DWORD *vect_addr;
> > DWORD *vect_cntl;
> >
> > VICIntEnClr = 1 << IntNumber; /* Disable Interrupt */
> > if ( IntNumber >= VIC_SIZE )
> > {
> > return ( FALSE );
> > }
> > else
> > {
> > /* find first un-assigned VIC address for the handler */
> > vect_addr = (DWORD *)(VIC_BASE_ADDR + VECT_ADDR_INDEX + IntNumber*4);
> > vect_cntl = (DWORD *)(VIC_BASE_ADDR + VECT_CNTL_INDEX + IntNumber*4);
> > *vect_addr = (DWORD)HandlerAddr; /* set interrupt vector */
> > *vect_cntl = Priority;
> > VICIntEnable = 1 << IntNumber; /* Enable Interrupt */
> > return( TRUE );
> > }
> > }
> >
> > and the last piece is the IRQ
> >
> > //------------
> > // Fonction: vRtcISR
> > // Desc : code de traitement de l'interruption
> > //------------
> > __irq __arm void vRtcISR( void )
> > {
> >
> > RTC_ILR |= ILR_RTCCIF;
> > g_ILR = ILR;
> >
> > RTC_INT_CallBack();
> > /* Clear the ISR in the VIC. */
> > VICVectAddr = 0;
> > FIO2SET = 0x00000080; // just another led for debug
> >
> > portEND_SWITCHING_ISR( pdTRUE );
> >
> > }
> >
> > the function : RTC_INT_CallBack(); just increment some counters
> >
> >
> > The problem was: I have environ 35 to 40 call to RTC_INT_CallBack() at
> > every seconds.
> >
> > I have interrupt if I put register CIIR = 0 !
> >
> > Something fire the interrupt many many time. But I can't find who
> > Help me please ( Or I kill (and eat) a puppy) :-))
> > I have lost 4 hours with google and many PDF manual before write this ! ( and a big lot of [ test, compil, flash and run ]on my card)
> >
> > some line of my dump :
> > t is my counter 19 is minute 41 is seconds (read from RTC)
> > you can see than t= jump 35 to 69 for the fist seconds
> > in place of 0 to 1, then 2 then 3 etc
> >
> > Console wait
> > t=35 19 41 g_ILR=00000000
> > t=69 19 42 g_ILR=00000000
> > t=103 19 43 g_ILR=00000000
> > t=138 19 44 g_ILR=00000000
> > t=173 19 46 g_ILR=00000000
> > t=207 19 47 g_ILR=00000000
> > t=242 19 48 g_ILR=00000000
> > t=276 19 49 g_ILR=00000000
> > t=310 19 50 g_ILR=00000000
> > t=345 19 51 g_ILR=00000000
> > t=379 19 52 g_ILR=00000000
> >
> > thank for all
>