11 years, 1 month ago.

How to simulate CAN-Bus errros like Stuff Error, CRC error and Form Error?

Currently i am trying to implement a protocol using CAN-error injection. In order to accomplish this task, i will need to simulate such errors on the can-bus over the time.

Is any way to simulate this kind of errors frames on the can-bus using mbed? I could not find this kind of function on the mbed.

As far as I know, all of those error detection methods are implemented in the hardware. As a user you have access to the error counters that you can use to see what is the current operating state of the device(error active, error passive, bus off). I don't think it is possible to produce such errors with the Mbed's CAN interface.

To be able to do that I think you would need to start implementing at least some parts of CAN-protocol yourself. I have to say I don't know what connections or components would be needed.

Someone correct me if I'm completely wrong.

Teemu

posted by Teemu Tuominiemi 05 Mar 2013

1 Answer

11 years, 1 month ago.

Hi Luis,

There will be some challenges ahead for you. Teemu is correct in that these errors are detected in the CAN hardware, and communicated to your software via the registers.

So, first I suggest a clean interface between the hardware and your software. Then, you could write some code to simulate faults in the hardware and use that to verify your application code executes properly.

To inject errors onto the bus, a few choices come to mind -

  • Buy a commercial CAN development tool. Some can controllably inject errors. Probably not an option for those on a smaller budget.
  • Use a stray wire to "scratch" across the network wires. The other end of this could be tied to ground for instance. You'll introduce a variety of errors - but obviously not very controllable. Connect a file (rasp) to ground, a wire to the CAN line, and then drag the other end of the wire on the file.
  • Create tiny pulses and with a simple transistor circuit tied to a CAN line, those pulses will disrupt the messages. This too won't be very controllable.
  • Programmatically generate a CAN frame with the errors you want to introduce by bit-banging. You could create a lookup table with some good and some bad frames (you'll probably have to compute the stuff bits and CRCs if you can't find known-good examples), and then the program need only choose one of the entries and "stream" those bits into a CAN transceiver for level shifting. At least for testing purposes, you should be able to set the bit rate for your CAN network to 10 kb/s which would ease the software, and perhaps use a SPI port in order to let the hardware manage the timing more precisely.