Timer 0 32b LPC 1114 - wrong RC5 code

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

Timer 0 32b LPC 1114 - wrong RC5 code

367 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Sun Apr 27 08:22:09 MST 2014
Hi everyone!

I need to do remonte control driver (using RC-5 code).
First I wrote a C code for my LPCXpresso LPC1769 (M3) because I have a lof of my own libraries for peripherals.
The external interrupt (on the falling egde) on one pin and a timer inside it and reading pin state.
Then colecting bits in MSB and LSB bytes and sengind them thru UART to the PC.

void EINT0_IRQHandler (void)
{
uint8_t  NumberOfBit = 0;
uint16_t RC5_Byte = 0;
uint8_t  MSB, LSB = 0;

Timer0_MicroSeconds (444);

for (NumberOfBit = 0; NumberOfBit <= 13; NumberOfBit++)
{
RC5_Byte |= ((LPC_GPIO2->FIOPIN & (1<<10)) >> NumberOfBit);
Timer0_MicroSeconds (889);
}
MSB = (RC5_Byte & 0xFF00) >> 8;
LSB = (RC5_Byte & 0x00FF) >> 0;

// Clear interrupt
LPC_SC->EXTINT = (1<<0);

UART0_SendByte (MSB);
UART0_SendByte (LSB);

}

int main (void)
{
UART0_Init ();
UART0_Bitrate (115200);

Timer0_Init (1);// value "1" just for init
EINT0_init ();

LPC_GPIO0->FIODIR |= (1<<22);
LPC_GPIO0->FIOSET |= (1<<22);

for (;;)
{
LPC_GPIO0->FIOPIN ^= (1<<22);
Timer0_MicroSeconds (500);

}
return (0);
}



Everything goes well.

Next I do the same on LPC1114 - the smaller version (M0) of ARM uC but given values are different than at LPC1769.

// main programm
int main (void)
{
Timer32b_0_Init ();// Set clock to the Timer 32-bit No. 0
UART_Init (115200);// Set UART bitrate as 115200 bps

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

LPC_GPIO0->DIR|= (1<<1);
LPC_GPIO0->DATA|= (1<<1);

LPC_GPIO0->DIR &=~(1<<4);// PIO 0.4 as input
LPC_GPIO0->DATA |= (1<<4);// PIO 0.4 with pull-up
LPC_GPIO0->IS &=~(1<<4);// Interrupt sensitive on edge change (not on level)
LPC_GPIO0->IBE &=~(1<<4);// Interrupt on pin PIO 0.4 is controlled through register GPIO0IEV
LPC_GPIO0->IEV&=~(1<<4);// falling egde on pin PIO 0.4 triggers an interrupt
LPC_GPIO0->IE |= (1<<4);// GPIO at PIO 0.4 Interrupt Enable

NVIC_EnableIRQ (EINT0_IRQn);// 31 PIO_0 GPIO interrupt status of port 0

for (;;)
{
Timer32b_0_ms (500);
LPC_GPIO0->DATA^= (1<<1);// toggle the LED on pin PIO 0.1 
}
 return (0);
}


void Timer32b_0_Init (void)
{
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
}

void Timer32b_0_us (uint32_t Microseconds)
{
    LPC_TMR32B0->TCR = 0x02;/* reset timer */
    LPC_TMR32B0->PR  = 0x00;/* set prescaler to zero */
    LPC_TMR32B0->MR0 = Microseconds * ((SystemCoreClock/(LPC_TMR32B0->PR+1))/1000000);
    LPC_TMR32B0->IR  = 0xff;/* reset all interrrupts */
    LPC_TMR32B0->MCR = 0x04;/* stop timer on match */
    LPC_TMR32B0->TCR = 0x01;/* start timer */

    /* wait until delay time has elapsed */
    while (LPC_TMR32B0->TCR & 0x01);
}

void PIOINT0_IRQHandler (void)
{
uint8_t  NumberOfBit = 0;
uint16_t RC5_Byte = 0;
uint8_t  MSB, LSB = 0;

if (LPC_GPIO0->MIS & (1<<4))// If set the interrupt at PIO 0.4
{

Timer32b_0_us (444);

for (NumberOfBit = 0; NumberOfBit <= 13; NumberOfBit++)
{
RC5_Byte |= ((LPC_GPIO0->DATA & (1<<4)) >> NumberOfBit);
Timer32b_0_us (889);
}

MSB = (RC5_Byte & 0xFF00) >> 8;
LSB = (RC5_Byte & 0x00FF) >> 0;

LPC_GPIO0->IC |= (1<<4);// Clear interrupt at PIO 0.4

asm ("nop");
asm ("nop");

UART_SendByte (MSB);
UART_SendByte (LSB);
}

return;
}


In both cases I get the toogle bit and 2 bytes... so it looks almost OK but the values are different.
My system core clock for LPC 1114 is 48 MHz so the Timer calculation for microseconds delay look also OK.

I don't know what's wrong with this.
I'll be very grateful for help in this case ;).
(If any data or information is missing I will write it down if you need.)




Labels (1)
0 Kudos
2 Replies

299 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Mon Apr 28 23:29:51 MST 2014
Hello everyone,

I changed pin from PIO 0.4 to PIO 1.9.

Everything works well.
The PIO 0.4 is a bit broken down.

Best regards,
Jacob
0 Kudos

299 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Apr 27 09:03:26 MST 2014

Quote: teslabox
I don't know what's wrong with this.
I'll be very grateful for help in this case ;).



With delays and (slow) UART function calls in ISR you are not really asking for help, aren't you?
0 Kudos