Common mistakes
Informative
Pitfalls when using the CAN driver, and how to avoid them. Each maps to a rule in Can — Requirements or an error in Errors.
Transmitting before the channel is STARTED.
Can_Transmiton aSTOPPEDchannel is rejected. Start the channel first, and re-check state after a bus-off (the driver forces the channel toSTOPPED).Freeing the payload too early. The driver copies your data, but you must keep
sduDataPtrvalid untilCanIf_OnTransmissionfires. Freeing or overwriting it earlier risks sending stale data (CHI-CAN-MUST-09).Stashing the RX pointer. Data given to
CanIf_OnReceptionis valid only until the callback returns (CHI-CAN-MUST-15). Copy what you need; don’t keep the pointer.Treating CAN_BUSY as an error.
CAN_BUSYmeans the mailbox is busy, not that the call failed — retry later. OnlyE_NOT_OKindicates a development error.Expecting automatic bus-off recovery. There is none (CHI-CAN-MUST-07). If you never call
Can_SetChannelState(..., STARTED)afterCanIf_OnError, the channel stays off the bus.De-initializing while STARTED.
Can_DeInitrequires every channel to beSTOPPED; otherwise it raisesCAN_DEVERR_STATE_TRANSITION. Stop channels first.Length that isn’t a valid DLC. The driver rounds up to the next valid DLC and pads (CHI-CAN-MUST-12) — make sure your
object_payload_lengthandfd_padding_valueare configured for the sizes you send.Forgetting to service polled events. If you configured
Pollingfor an event, you must callCan_PollFunction/Can_CyclicFunctioncyclically, or that event is never handled.