HardFault when receive CAN message!

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

HardFault when receive CAN message!

577 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by trongtinbk on Sun Dec 04 21:34:29 MST 2011
I used 2 LPC1769 to communicate.I connected CAN1 of 2 LPC1769 through 2 CAN tranceiver(TI SN65HVD251 IC CAN RXTX 5V). After receive only one message from LPC1769 no1, LPC1769 no2 jump to HardFault_Handler(void). I checked the ID and data of the first message, everything was ok! After released RX buffer in CAN_ISR_Rx1 function it jump to HardFault_Handler function.(I use CAN baudrate 125K).

Please help me!
0 Kudos
11 Replies

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Dec 06 05:23:28 MST 2011

Quote:

I still don't understand why! I don't use CAN2, why I must init it!

You are using it in your CAN interrupt :eek: Stepping forward with your debugger can help you to find the critical lines:
 if ( LPC_CAN2->GSR & (1 << 6 ) )
  {
    /* The error count includes both TX and RX */
    CAN2ErrCount = LPC_CAN2->GSR >> 16;
  }
Instead of setting PCONP bit in CAN_Init( LPC_CAN2,...) you can comment this lines out, or use #ifdef...#endif to exclude this part.

Using Peripheral registers without setting their PCONP bit can always case a HardFault, so it's always a good idea to check PCONP status of all used Peripherals with your debugger


Quote:

...debugger always suspends at a line...

Are there breakpoints left in your 'Breakpoints' View?

Also Compiler Optimization can result in funny behaviour :rolleyes:

See http://support.code-red-tech.com/CodeRedWiki/CompilerOptimization
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by trongtinbk on Tue Dec 06 03:13:52 MST 2011
OMG! After init CAN2, it didn't jump to HardFault anymore :). I still don't understand why! I don't use CAN2, why I must init it! I try 3 different LPC1769 and this error always happens.:confused:

I still a small problem! When I debug, debugger always suspends at a line in main.c of 1769SLAVE project although I didn't create any breakpoint.I hadn't sent any CAN messages before so CAN1RxDone can't equal TRUE.:eek:
while(1)
{
if(CAN1RxDone == TRUE)    // debugger suspended here
{
CAN1RxDone = FALSE;
CANCheck();
}
}

return 0;
}

Thank for your help!:)
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 05 11:20:52 MST 2011
#1 Init CAN2 :rolleyes: 
#2 Use your debugger to step until the hard fault appears :eek:

I suspect your problems are the result of reading CAN2 registers in CAN interrupt without enabling its PCONP bit :eek:

See user manual: 4.8.9 Power Control for Peripherals register (PCONP - 0x400F C0C4)

Quote:

Important: valid read from a peripheral register and valid write to a peripheral
register is possible only if that peripheral is enabled in the PCONP register!

0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by trongtinbk on Mon Dec 05 10:56:49 MST 2011
Oh sorry! That's my fault. But when replace CAN2RxDone with CAN1RXDone, it still not working. I use LPC-Link to debug, set some breakpoints then I realized that SLAVE jump to CAN_ISR_Rx1 only one time (when receives the first message). And jump to HardFault_IRQHandler right affter that, instead of go to main loop anh clear CAN1RxDone.
Do you know what it mean?
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 05 10:22:18 MST 2011
Init CAN1
 CAN_Init( LPC_CAN1,BITRATE125K30MHZ );
and reading CAN2 will not work :confused:
 if(CAN2RxDone==TRUE)
  {
   CAN2RxDone=FALSE;
   CANCheck();
  }
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by trongtinbk on Mon Dec 05 08:32:08 MST 2011
I use LPCXpresso v4.05. I try CAN example in "MCB1700 Sample Code Bundle for LPC1769 Peripherals using LPCXpresso". It's so simple and works well with CAN1 and CAN2 in 1 MCU. I tested this example and everything ok! But when I use 2 MCU everything went wrong!
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 05 07:42:31 MST 2011
#1 Are you working with LPCXpresso?

#2 I'm not very familiar with this sample, so is there a special reason why you use this sample and don't use a 1769 CAN sample?

#3 To find problems, there are options like 'local self test' and 'self reception' which can be used to control receiving and transmitting. Did you try to use them already?
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by trongtinbk on Mon Dec 05 07:21:41 MST 2011
I changed my main_slave.c

Quote:
while(1){
if(CAN2RxDone==TRUE){
CAN2RxDone=FALSE;
CANCheck();
}
}



And I used CAN_SetACCF( ACCF_BYPASS ) instead of CAN_SetAFLUT() but everything still the same :(
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 05 05:02:16 MST 2011
What's that :eek:

Quote:

CAN1RxDone = TRUE;
CANCheck();
LPC_CAN1->CMR = 0x01 << 2; /* release receive buffer */

#1 This Keil samples use CANxRxDone flags to keep this ISRs short and do the work outside in main loop.[INDENT]So use a simple
if(f_CAN1Rx == TRUE)
 {
  f_CAN1Rx = FALSE;
  ...do whatever you want here...    
}
in your main loop...
[/INDENT]#2 I would suggest to use CAN_SetACCF(ACCF_BYPASS) instead CAN_SetAFLUT() to avoid problems.
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by trongtinbk on Mon Dec 05 04:26:09 MST 2011
[ATTACH]611[/ATTACH]

[ATTACH]612[/ATTACH]

[ATTACH]613[/ATTACH]

Here's my projects. I use CMSIS2.00 but in inc folder 1 add another file: type.h

My MASTER will send some message, my SLAVE receive and store data( use CANCheck function in CAN_ISR_Rx1 function)
0 Kudos

549 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Dec 05 02:47:35 MST 2011
Could be helpful if you post your code or tell us which sample you have used :rolleyes:
0 Kudos