I have two TMS320F28379Ds communicating over the CAN bus.
They are setup in a master - slave configuration, meaning that only when the master MCU sends data(data request frame) , the slave MCU will send back the requested data.
The master periodically sends the data request frame, (and the slave responds).
This is the initialization function of the CAN bus. Thie same function runs on both the master and slave MCUs
void HAL_setupCAN_CTRL(uint32_t base)
{
//
// Initialize the CAN controllers
//
CAN_initModule(CTRL_BRD_CAN);
//
// CAN bit rate is 500 KHz , derived from the system clock
//
CAN_setBitRate(CTRL_BRD_CAN, DEVICE_SYSCLK_FREQ, 500000, 16);
CAN_disableInterrupt(CTRL_BRD_CAN, CAN_INT_IE0 | CAN_INT_ERROR |
CAN_INT_STATUS);
//
// Start CAN module
CAN_startModule(CTRL_BRD_CAN);
}
1.When both the master and slave MCUs are active(powered on at the same time) and then the can bus is properly initialized, everything works!,
2.When the slave is powered on first, and then the master is powered on second, communication is established after the CAN bus in the master is initialized.!
3.But the other way around, when the master is powered on first and then the slave is powered on second , the slave does not get the data request frames any more from the Master. Probing the Master's TXB pin, i don't see any activity on that line. Its as though the Master's CAN module has not initialized. Any idea why does this happen?
Looking at the Master's error status i only see the LEC bit set to 7 in CAN_ES register.
One way to get around this is, in the Masters side, if i don't recieve data from the slave MCU, i just re-initialize the Can bus again and the bus starts working:
//If there is no reception of data for more than 200 ms, reset the can module
if(canReTryCounter > CAN_DELAY(CAN_RETRY_TIME))
{
//Reset the can bus configuration
HAL_setupCAN_CTRL(CTRL_BRD_CAN);
canReTryCounter = 0;
}
Is there a better way to detect that there is no can bus available? I am not talking about the CAN errors here, but the bus avalability itself.
Thanks,
AK