![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
Hi,
I have a very simple program in which I isolated my problem. When I try to do anything with Timer 2 or Timer 3 on my board I get hard fault. The code is as follows: Code:
int main(void)
{
// P1[26] as cap0.0
PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL;
PinCfg.Pinmode = PINSEL_PINMODE_PULLDOWN;
PinCfg.Funcnum = PINSEL_FUNC_3;
PinCfg.Portnum = PINSEL_PORT_1;
PinCfg.Pinnum = PINSEL_PIN_26;
PINSEL_ConfigPin(&PinCfg);
// P3[25] as mat0.0
PinCfg.Funcnum = PINSEL_FUNC_2;
PinCfg.Portnum = PINSEL_PORT_3;
PinCfg.Pinnum = PINSEL_PIN_25;
PINSEL_ConfigPin(&PinCfg);
// P1[18] as cap1.0
PinCfg.Funcnum = PINSEL_FUNC_3;
PinCfg.Portnum = PINSEL_PORT_1;
PinCfg.Pinnum = PINSEL_PIN_18;
PINSEL_ConfigPin(&PinCfg);
// P1[22] as mat1.0
PinCfg.Pinnum = PINSEL_PIN_22;
PINSEL_ConfigPin(&PinCfg);
// P0[4] as cap2.0
PinCfg.Portnum = PINSEL_PORT_0;
PinCfg.Pinnum = PINSEL_PIN_4;
PINSEL_ConfigPin(&PinCfg);
// P4[28] as mat2.0
PinCfg.Funcnum = PINSEL_FUNC_2;
PinCfg.Portnum = PINSEL_PORT_4;
PinCfg.Pinnum = PINSEL_PIN_28;
PINSEL_ConfigPin(&PinCfg);
// P0[23] as cap3.0
PinCfg.Funcnum = PINSEL_FUNC_3;
PinCfg.Portnum = PINSEL_PORT_0;
PinCfg.Pinnum = PINSEL_PIN_23;
PINSEL_ConfigPin(&PinCfg);
// P0[10] as mat3.0
PinCfg.Pinnum = PINSEL_PIN_10;
PINSEL_ConfigPin(&PinCfg);
// - CCR:CAP0RE = 1 - capture rising edge
// - CCR:CAP0FE = 0 - don't capture falling edge
// - CCR:CAP0I = 1 - generate interrupt
LPC_TIM0->CCR = 0b101;
LPC_TIM1->CCR = 0b101;
//LPC_TIM2->CCR = 0b101; // if I uncomment either of these 2 lines
//LPC_TIM3->CCR = 0b101; // I get a hard fault
while(1);
return 0 ;
}
What's going on? Please help. ps: I'm attaching my whole test program. |
|
#2
|
|||
|
|||
|
Hm, I think this might be the problem:
"1. Power: In the PCONP register (Table 46), set bits PCTIM0/1/2/3. Remark: On reset, Timer0/1 are enabled (PCTIM0/1 = 1), and Timer2/3 are disabled (PCTIM2/3 = 0)." My solution is to add CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCTIM2, ENABLE); Sorry for posting questions which I end up answering myself... but I really tried to find the answer BEFORE I posted... |
|
#3
|
|||
|
|||
|
Using unpowered peripherals is causing Hard Faults. So PCONP is the first thing to check
|
![]() |
| Thread Tools | |
|
|