NXP Semiconductors logo
LPCXpresso Logo

Reply
 
Thread Tools
  #1  
Old 08-07-2012, 06:21 PM
dragilla dragilla is offline
Senior Member
 
Join Date: Nov 2011
Location: Warsaw, Poland
Posts: 172
dragilla is on a distinguished road
Default LPC_TIM2 hard fault on lpc1769

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 ;
}
If try to set CCR or PR or CTCR on TIM2 or TIM3 I get a hard fault.
What's going on? Please help.

ps: I'm attaching my whole test program.
Attached Files
File Type: zip test.zip (131.4 KB, 0 views)
Reply With Quote
  #2  
Old 08-07-2012, 06:31 PM
dragilla dragilla is offline
Senior Member
 
Join Date: Nov 2011
Location: Warsaw, Poland
Posts: 172
dragilla is on a distinguished road
Default

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...
Reply With Quote
  #3  
Old 08-07-2012, 06:36 PM
Zero Zero is offline
Senior Member
 
Join Date: Dec 2009
Location: far away
Posts: 2,625
Zero is on a distinguished road
Default

Using unpowered peripherals is causing Hard Faults. So PCONP is the first thing to check
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 01:16 PM.