Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to generate CAN bus error using STM32?

For one of my project, I would like to generate some CAN bus errors (e.g. bit stuffing or CRC error).

This is just a small idea I had, but do you think it is possible to achieve ? I know all the protocol stuffs are handled by the CAN driver, but I am also not an expert in CAN communication, so maybe I have a little hope that this error generation can be achievable. What do you think ?

I am using a STM32 microcontroller and TJA CAN transceiver.

like image 679
Stabilo Avatar asked Mar 04 '23 05:03

Stabilo


1 Answers

This is not handled by software at all, but by the on-chip CAN controller hardware. You will not be able to add things like stuffing or CRC errors with software alone, though it can be achieved by various hardware tricks.

One easy way to generate a whole lot of errors is to only have one node on the bus, or to short CAN High/Low. You'll rapidly go error active then error passive if you do this though.

More subtle ways is to pull Tx/Rx lines between the MCU and transceiver to wrong levels. If you connect one of these to an external GPIO pin and then sneak out a pulse directly after storing the message in the CAN buffer, you'll cause errors. Particularly if longer than 6 bits = stuff error. These will most likely be well in sync with the protocol, so this is probably what you want. You might have to add like 10k in series to the actual tx/rx pins so they get weaker drive strength than the GPIO.

Another method is to have 2 nodes sending identical arbitration fields (ID, RTR + misc bits) at once, but different data. This is achivable from software alone but it means you need to have 2 dumb nodes doing nothing but sending the same messages over and over at 100% bus load.

like image 84
Lundin Avatar answered Mar 16 '23 00:03

Lundin