Hi, this is my first thread in this forum and at the beginning i want to apologize for my English OK, I've just written small program with timer0 and interrupt. I want to toggle one of the LED on board, but...It doesn't work and I really don't know what's wrong with this code. Each LED is lit and nothing more... Could you help with it ? Thank you in advance and best regards :)
#ifdef __USE_CMSIS #include "LPC17xx.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 ; // TODO: insert other include files here // TODO: insert other definitions and declarations here int main(void) { LPC_GPIO2->FIODIR |= 1 << 29; LPC_SC->PCONP |= 1 << 1; LPC_SC->PCLKSEL0 |= 1 << 3; LPC_TIM0->TCR |= 0x00000002; LPC_TIM0->MCR |= 0x00000003; LPC_TIM0->MR0 |= 6000000; NVIC_EnableIRQ(TIMER0_IRQn); LPC_TIM0->TCR |= 0x00000001; while(1){} return 0 ; } void TIMER0_IRQHandler (void) { if((LPC_TIM0->IR & 0x01) == 0x01) { LPC_TIM0->IR |= 1 << 0; LPC_GPIO2->FIOPIN ^= 1 << 29; } }
OK, It works ! Configuration was bad ;) and more specifically the line:
LPC_TIM0->TCR = 0x00000002; must be followed by LPC_TIM0->TCR &= 0 << 1;
As I said, timer didn't enetr to interrupt but now everything is OK.
Your original post does not even show
TCR = 0x00000002
and if you follow it with
TCR &= 0 << 1
then you're writing 0 to TCR so why write 2 in the first place?
Generally I wrote the same program with timer and interrupt on assembler and there I had loading by LDR 0x00000002 value...I don't know why the same configuration on asm is OK and after moving to C language it dido't work...
you said@
...I don't know why the same configuration on asm is OK and after moving to C language it dido't work...
bug in compiler???????????
"bug in compiler???????????"
Skip the many ???? - they are not needed.
The posted code was buggy - no need to suggest a bug in the compiler when the source code has errors.
I've just checked one thing - &= operator and in all it doesn't necessary. There could be common "=" and it works too.
Compiler ? Timer on asm was written on Keil, but now I'm writing on LPCXpresso ;) I don't think so about compiler...it's about the bits.