I have been struggling for some while now with initialization of the CANIF module on an AT32UC3C1512C.
I'm using the Atmel ASF code.
Some of the time the CANIF module comes up nicely, and everything works as expected.
But sometimes can_init() fails, returning CAN_CMD_REFUSED. This can only mean that the CANIF_channel_enable_status() call failed after the delay period after the CANIF_enable() call. In other words, the CES bit did not go high as expected.
I have a loop around the call to can_init(), and if I call it often enough it generally seems to succeed eventually. But sometimes it takes more than a million calls before that happens.
I tried making the delay period in can_init() much longer (1000 times), but that didn't make any difference.
When the initialization works, the CAN module goes on to work beautifully. That suggests the configuration can't be all that far wrong.
Another oddity is that when the initialization fails, it tends to be persistent. For example, right now I cannot get the CAN module to start at all. But a couple of days ago I could not get it to fail.
Any idea why the CES bit might fail to come up sometimes?