CAN baud rate change, device is restarting continuously!
Facing issue with CAN baud rate change!
1. The Master and slave devices are communicating at baud rate of 1Mbps.
2. If I change the baud rate of Master device to any other baud rate(like, 250kbps, 500kbps,125kbps,50kbps) then master device contiguously restarting the device! Got to know that, it is restarting due to watch dog timer!
3. To resolve the restart issue, added the timeout logic in the while loop where it is entering into intialize mode and normal mode.
4. I gave CAN_TIMEOUT as 1000ms, If I add timeout logic, device is not communicating with slave and data is not exchanging due while timeout logic
5. Tried with different logic by calling HAL_NVIC_SystemReset(); in the timeout logic.
static UINT32 CanFunctin(void)
{
UINT32 tickstart = 0,tickstart1=0;
// static UINT32 BaudRateChange=0;
UINT32 error=0;
// Exit Sleep mode and enter Initialize mode.
CAN1->MCR &= ~CAN_MCR_SLEEP;
CAN1->MCR |= CAN_MCR_INRQ;
tickstart = FPGA_GET_FRT_UINT32;
// Wait for Initialize mode acknowledge.
while ((CAN1->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
{
if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE)
{
uint32_t esr = CAN1->ESR;
printf("Err-CanPortInit: Timeout waiting to enter initi mode\n");
if (esr & CAN_ESR_BOFF) printf("CanPortInit - Bus-Off condition detected\n");
if (esr & CAN_ESR_EPVF) printf("CanPortInit - Error Passive mode\n");
if (esr & CAN_ESR_EWGF) printf("CanPortInit - Error Warning level reached\n");
return error;
}
}
CAN1->MCR |= CAN_MCR_ABOM; // Auto Bus-Off Management
// Initialize Master Control Register.
CAN1->MCR |= MCR_INZ;
// Initialize CAN bit timing.
CAN1->BTR = BTR_INZ | CanBaud[CanBaudRate] | SJW_INZ(CanSjw);
if (CAN1->ESR & CAN_ESR_BOFF)
{
CAN1->ESR = 0; // Clear error flags
}
// Enter Normal mode.
CAN1->MCR &= ~CAN_MCR_INRQ;
tickstart1 = FPGA_GET_FRT_UINT32;
// Wait for Normal mode acknowledge.
while ((CAN1->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
{
if ((HAL_GetTick() - tickstart1) > CAN_TIMEOUT_VALUE)
{
uint32_t esr = CAN1->ESR;
printf("Err-CanPortInit: Timeout waiting to enter NORMAL mode\n");
if (esr & CAN_ESR_BOFF) printf("CanPortInit - Bus-Off condition detected\n");
if (esr & CAN_ESR_EPVF) printf("CanPortInit - Error Passive mode\n");
if (esr & CAN_ESR_EWGF) printf("CanPortInit - Error Warning level reached\n");
error=1;
CAN1->ESR = 0;
RCC->APB1RSTR |= RCC_APB1RSTR_CAN1RST;
RCC->APB1RSTR &= ~RCC_APB1RSTR_CAN1RST;
__NOP(); __NOP(); __NOP();
HAL_NVIC_SystemReset();
CAN1->ESR = 0;
return error;
}
}
// Enable CAN interrupt sources.
CAN1->IER = IER_INZ;
return error;
}Thank you in advance for any suggestions!
