CAN programming - program freezes after restart

I have a sketch which was written to allow a reverse camera to function correctly in a different year of car. It works by reading data from the HS-CAN bus via interrupt and then every 150ms sends a recalculate CAN message out on the MS-CAN bus.

This all seems to work great - except if the car has been stopped and restarted again (but not every time). at this point the code appears to freeze and requires a reset to start working again.

The problem appears to be in the interrupt of sending out the MS-CAN message - after a car restart it stops sending it out.

I can't see anything obviously wrong - but it seems to be to do with the sleep functions, because if i remove the set_sleep_mode(SLEEP_MODE_IDLE) from the receiving loop, the problem doesn't happen.

Anyone give me any ideas why and a better way of doing this?

rear camera.txt (2.51 KB)

Why do you need sleep mode?

Because the device is permanently connected to the vehicle, it needs to consume as little power as possible when not used.

I have another unit which does not use sleep and it has caused a flat battery when the car has been left for a couple of days.

Also I didn't write the code so I can't give a definitive answer why it was done in this way - other than my thoughts above :slight_smile:

Finally, it appears the above change doesn't stop it freezing - the only way to stop it is to remove wdt_disable() from the send routine