AnsweredAssumed Answered

LPC1768 CAN-BUS init issue

Question asked by Federico Testolin on Jun 14, 2019

hi, we have many products that sometimes fail the canbus baudrate settings:

"static void can_SetBaudrate (LPC_CAN_TypeDef *CANx, uint32_t baudrate)"

i attach the file we use to do the init of baudrate. almost all the time all is working fine, to replicate the issue, we put a board and power it on/off many times and usually after 1h we can replicate the issue. we found that sometimes, for unknow reason, the register "CANx->BTR" is not set! we tried also to make a while loop until the register is set but it never takes values when the problem happen.....

code:

/* Enter reset mode */

CANx->MOD = 0x01;

/* Set bit timing *Default: SAM = 0x00; * SJW = 0x03; */

CANx->BTR = (TSEG2<<20)|(TSEG1<<16)|(3<<14)|BRP;

/* Return to normal operating */

CANx->MOD = 0;

i looked on errata sheet but seem there is nothing about can. we were able to improve the issue but not to fix it completely. all other pheriperials of nxp mcu are working fine, power supply is good, no ripple no spikes.

here the code we use to init the can peripherial

void task_can_init(void) {

CAN_Init(LPC_CAN1, 500000 );

CAN_IRQCmd(LPC_CAN1, CANINT_RIE, ENABLE);

CAN_IRQCmd(LPC_CAN1, CANINT_TIE1, ENABLE);

CAN_IRQCmd(LPC_CAN1, CANINT_TIE2, ENABLE);

CAN_IRQCmd(LPC_CAN1, CANINT_TIE3, ENABLE);

CAN_IRQCmd(LPC_CAN1, CANINT_EIE, ENABLE);

CAN_IRQCmd(LPC_CAN1, CANINT_EPIE, ENABLE);

CAN_IRQCmd(LPC_CAN1, CANINT_BEIE, ENABLE);

CAN_SetAFMode(LPC_CANAF,CAN_AccBP);

//Enable CAN Interrupt

NVIC_SetPriority( CAN_IRQn, 1 );

NVIC_EnableIRQ(CAN_IRQn); }

in main.c this is the code:

//*******************// //*** INIT CANBUS ***// //*******************//

task_can_init( );

PINSEL_ConfigPin( EXT_CAN_TX_uP_Port, EXT_CAN_TX_uP_Pin, EXT_CAN_TX_uP_Func );

PINSEL_ConfigPin( EXT_CAN_RX_uP_Port, EXT_CAN_RX_uP_Pin, EXT_CAN_RX_uP_Func );

//*******************//

init is made at startup we have 300k machines now that MAY have this problem, and we are in production, so number will increase. hope you have some suggestion

Attachments

Outcomes