LPC1768 problem with timer0

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC1768 problem with timer0

1,155件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by damiandoles on Thu May 03 03:11:34 MST 2012
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...Could you help with it ?

/*
===============================================================================
 Name        : main.c
 Author      : 
 Version     :
 Copyright   : Copyright (C) 
 Description : main definition
===============================================================================
*/

#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;
    }
}
0 件の賞賛
返信
2 返答(返信)

1,119件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu May 03 10:52:17 MST 2012
Back in office and back to work:

Error #1:[INDENT]What's obviously wrong here is your timer setup in TCR.
[/INDENT][INDENT]Reset(1<<1) and Enable(1<<0) at the same time is confusing your timer :confused:

Since TCR Reset value is 0, you don't need to reset this register.

Just enable it (after enabling Interrupt) with:

 LPC_TIM0->TCR[B][COLOR=Red] =[/COLOR][/B] 1; //enable timer
[/INDENT]Error #2:[INDENT]I'm not sure what you are toggling here. My 1769 has no P2[29] :eek:

Changing it to P1[29] shows a wonderful signal

Toggling as desired with (CCLK/2)/6E6 = 50MHz/6E6 = 8.33Hz
[/INDENT]
0 件の賞賛
返信

1,119件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu May 03 04:13:00 MST 2012
Where is your Interrupt routine (ISR) and what is not working?

A simple sample has been posted here: http://knowledgebase.nxp.com/showthread.php?t=2059
0 件の賞賛
返信