How can dedect bus off state an other can bus error im lpc 54616? im try in mcan interrupt transfer like this:
case kStatus_MCAN_ErrorStatus:
{
uint32_t bo, lec;
if ((base->PSR&CAN_PSR_BO_MASK)>>CAN_PSR_BO_SHIFT)
{
/* Reset INIT bit to enter normal mode. */
base->CCCR &= ~CAN_CCCR_INIT_MASK;
while (0U != (base->CCCR & CAN_CCCR_INIT_MASK))
{
}
while ( (((base->PSR&CAN_PSR_LEC_MASK)==5) ) || (((base->PSR&CAN_PSR_BO_MASK)>>CAN_PSR_BO_SHIFT==1)) )
{
}
MCAN_Init(EXAMPLE_MCAN, &mcanConfig, MCAN_CLK_FREQ);
//MCAN_Deinit(base);
}
//MCAN_Init(EXAMPLE_MCAN, &mcanConfig, MCAN_CLK_FREQ);
//MCAN_Deinit(base);//Init(EXAMPLE_MCAN, &mcanConfig, MCAN_CLK_FREQ);
}
But PSR_BO always is 1
Hi, Ali,
I see that you just want to handle various error.
You can manipulate the NCAN0_RST in PRESETCTRL1 REG to reset the CAN module, then reinitialize the CAN module.
Hope it can help you
BR
XiangJun Rong
i can solve this problem . I can grab error in calback function. after ican restart can modul with bus_off. But important function sendnonblocking method. if user use like sdk is hangup in while statement
while (!txComplete)
{
}
txComplete = false;
user must control sendnonblocikng methode return value. If valu is sucsec u can use while statement.
sts=MCAN_TransferSendNonBlocking(EXAMPLE_MCAN, &mcanHandle, &txXfer);
switch (sts)
{
case kStatus_Success:
{
while (!txComplete)
{
}
txComplete = false;
}
break;
case kStatus_Fail:
{
psr=EXAMPLE_MCAN->PSR&CAN_PSR_LEC_MASK;
ecer=EXAMPLE_MCAN->ECR&CAN_ECR_TEC_MASK;
busof=(EXAMPLE_MCAN->PSR&CAN_PSR_BO_MASK)>>CAN_PSR_BO_SHIFT;
ccr=EXAMPLE_MCAN->CCCR;
sts=0;
}
break;
case kStatus_MCAN_TxBusy:
{
}
default:
break;
}
call back func:
static void mcan_callback(CAN_Type *base, mcan_handle_t *handle, status_t status, uint32_t result, void *userData)
{
BaseType_t xHigherPriorityTaskWoken;
/* The xHigherPriorityTaskWoken parameter must be initialized to pdFALSE as
it will get set to pdTRUE inside the interrupt safe API function if a
context switch is required. */
xHigherPriorityTaskWoken = pdFALSE;
/* 'Give' the semaphore to unblock the task. */
/* Pass the xHigherPriorityTaskWoken value into portYIELD_FROM_ISR(). If
xHigherPriorityTaskWoken was set to pdTRUE inside xSemaphoreGiveFromISR()
then calling portYIELD_FROM_ISR() will request a context switch. If
xHigherPriorityTaskWoken is still pdFALSE then calling
portYIELD_FROM_ISR() will have no effect. The implementation of
portYIELD_FROM_ISR() used by the Windows port includes a return statement,
which is why this function does not explicitly return a value. */
// printf("Callback status: 0x%x", status);
//printf(" IR: 0x%x \r\n", base->IR);
switch (status)
{
case kStatus_MCAN_RxFifo0Idle:
{
xSemaphoreGiveFromISR( semaphoreRX, &xHigherPriorityTaskWoken );
rxComplete = true;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
break;
case kStatus_MCAN_TxIdle:
{
xSemaphoreGiveFromISR( semaphorum, &xHigherPriorityTaskWoken );
txComplete = true;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
break;
case kStatus_MCAN_ErrorStatus:
{
if (EXAMPLE_MCAN->CCCR &= CAN_CCCR_INIT_MASK)
{
EXAMPLE_MCAN->CCCR &= ~CAN_CCCR_INIT_MASK;
while (0U != (EXAMPLE_MCAN->CCCR & CAN_CCCR_INIT_MASK))
{
}
}
mcanreset();
//txError=true;
txComplete = true;
xSemaphoreGiveFromISR( semaphorum, &xHigherPriorityTaskWoken );
txComplete = true;
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
default:
break;
}
}
in calback function i send xsemaphore to my rtos but this is only evaluate .
sory this code only evaluate. im writing all is next day.
Hi, Ali,
For the CAN bus off error, pls check the CAN bus network, the CANx_TD and CANx_RD must be connected to a CAN transceiver, as Frank said that the 120 ohm terminating resistor between CAN_H and CAN_L pins of CAN transceiver is required.
BR
XiangJun Rong
My can cominication work.İ neede manupilating can buss error state. I can try in sdk example . Can work normal but if i can short circuit can bus can goes bus off state . How can i reset cominication and other error state.
Check the error counter values (TEC and REC).
These values are implemented according to the CAN bus standard.
"Bus off" means a counter (usually TEC) has hit 255.
It seems you have a physical problem, perhaps your termination is not correct, or you swapped CANH and CANL at one bus participant.