LPC11C24 can on-chip error handler

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

LPC11C24 can on-chip error handler

708 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by signumx on Mon May 14 12:13:25 MST 2012
Hi,

I'm using the CAN on-chip api and everything is working fine when I start my system.  I want to be able to detect and handle errors if, for instance, the communication cable to my module is cut.  When I test that, I can see that the CAN_error callback function is called the first time (by inserting a breakpoint in that function).  I plug my cable back, the communication restarts but if I remove it again, the CAN_error is never called again.

I thought of resetting the CANSTAT register but I'm apparently not allowed to  do so.  I also tried to call the initCan function inside the error handler but it does not help.  How do I either reinitialize the error flags or the whole CAN controller?

Thank you,
Jeff
0 Kudos
5 Replies

579 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Fri Mar 21 02:20:29 MST 2014
As described in UM:


Quote:
On-chip RAM from address 0x1000 0050 to [color=#f00]0x1000 00B8[/color] is used by the CAN API.



it's enough to reserve:
//reserve CAN ROM-RAM 0x1000 0050 - 0x1000 00B9
__BSS(RESERVED) char CAN_driver_memory[0xC0];

which was described long time ago here:

http://www.lpcware.com/content/forum/how-to-reserve-lpc11cxx-ram

0 Kudos

579 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by npl102 on Thu Mar 20 12:53:41 MST 2014
Had same problem, see: 

http://www.lpcware.com/content/faq/lpcxpresso/reserving-ram-rom-drivers

for reserving RAM for ROM CAN driver.
0 Kudos

579 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tomicacar on Wed Mar 12 02:12:36 MST 2014
Hello, I have similar problem, my code never goes to CAN_error callback function.

Have you solved your problem?

Thank you,

Tomica.
0 Kudos

579 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by signumx on Tue May 15 05:18:11 MST 2012
Here's the code.  It's basically the same as the lpcXpresso can on-chip example.

ROM **rom = (ROM **)0x1fff1ff8;

CAN_MSG_OBJ msg_obj;

static uint32_t noAnswerErrorCount = 0;

/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = {
  0x00000005UL, // CANCLKDIV
  0x00000501UL  // CAN_BTR 500kbps
};

/* Callback function prototypes */
void CAN_rx(uint8_t msg_obj_num);
void CAN_tx(uint8_t msg_obj_num);
void CAN_error(uint32_t error_info);

/* Publish CAN Callback Functions */
CAN_CALLBACKS callbacks = {
   CAN_rx,
   CAN_tx,
   CAN_error,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
};

/*CAN receive callback */
/*Function is executed by the Callback handler after
a CAN message has been received */
void CAN_rx(uint8_t msg_obj_num){

noAnswerErrorCount = 0;

/* Determine which CAN message has been received */
msg_obj.msgobj = msg_obj_num;

/* Now load up the msg_obj structure with the CAN message */
(*rom)->pCAND->can_receive(&msg_obj);

return;
}

/*CAN transmit callback */
/*Function is executed by the Callback handler after
a CAN message has been transmitted */
void CAN_tx(uint8_t msg_obj_num)
{
return;
}

/*CAN error callback */
/*Function is executed by the Callback handler after
an error has occured on the CAN bus */
void CAN_error(uint32_t error_info)
{
noAnswerErrorCount++;
return;
}

/*CAN interrupt handler */
/*The CAN interrupt handler must be provided by the user application.
It's function is to call the isr() API located in the ROM */
void CAN_IRQHandler (void){
  (*rom)->pCAND->isr();
}

void initCan(void)
{
bool result = true;

/* Initialize the CAN controller */
(*rom)->pCAND->init_can(&ClkInitTable[0], 1);

/* Configure the CAN callback functions */
(*rom)->pCAND->config_calb(&callbacks);

/* Disable automatic repetition */
LPC_CAN->CNTL |= CTRL_DAR;

/* Enable the CAN Interrupt */
NVIC_EnableIRQ(CAN_IRQn);

noAnswerErrorCount = 0;
}

void speedCanRequest(void)
{
msg_obj.msgobj  = 0;
msg_obj.mode_id = 0x7DF;
msg_obj.mask    = 0x0;
msg_obj.dlc     = 8;
msg_obj.data[0] = 0x02;
msg_obj.data[1] = 0x01;
msg_obj.data[2] = 0x0D;
msg_obj.data[3] = 0x55;
msg_obj.data[4] = 0x55;
msg_obj.data[5] = 0x55;
msg_obj.data[6] = 0x55;
msg_obj.data[7] = 0x55;
(*rom)->pCAND->can_transmit(&msg_obj);

msg_obj.msgobj = 1;
msg_obj.mode_id = 0x7E8;
msg_obj.mask = 0x7E0;
(*rom)->pCAND->config_rxmsgobj(&msg_obj);
}


So I call the function speedCanRequest once per second and the communication goes smoothly with my CAN emulator.  Unplugging the cable will increment the noAnswerErrorCounter variable once but repeating the operation won't affect it anymore.

Thanks,
Jeff
0 Kudos

579 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Mon May 14 22:17:09 MST 2012

Quote: signumx
Hi,

I'm using the CAN on-chip api and everything is working fine when I start my system.  I want to be able to detect and handle errors if, for instance, the communication cable to my module is cut.  When I test that, I can see that the CAN_error callback function is called the first time (by inserting a breakpoint in that function).  I plug my cable back, the communication restarts but if I remove it again, the CAN_error is never called again.

I thought of resetting the CANSTAT register but I'm apparently not allowed to  do so.  I also tried to call the initCan function inside the error handler but it does not help.  How do I either reinitialize the error flags or the whole CAN controller?

Thank you,
Jeff


@Signumx..Hi..!!!

Can you please share the code with us.


Thanks & Regards....!!!:)
0 Kudos