Help wanted - Automatic CAN Baud detection

#1

We were were thinking that one feature that would be nice to have is an automatic CANbus speed detection routine. Cars have different CAN speeds, use either 11 or 29-bit identifiers and might even have multiple channels on the OBD2 port. It would be nice for M2 to be able to figure out how to communicate with an unknown car’s CAN bus. Something faster than trial/error would be cool.

Maybe stay in “Listen” mode while detection is happening, and then set the baud/identifier before going into normal mode?

Anyone interested in giving this a shot?

#2

Probably just need to have baud rate detection only…

I wouldnt bother about auto-detecting 11/29-bit in the setup loop and “fixing” it there…particularly because on GM 33.3k single-wire-CAN, they use mixed 11-bit and 29-bit ID’s simultaneously.

I think CollinK’s CAN library for the Arduino Due already supports auto-baud detection??

#3

Good point regarding the 11/29-bit! Just detecting baud would be cool enough. I’ll need to look to see if Collin’s library does that already. Do you know where that is?

I found this:

void enable_autobaud_listen_mode();

Here: https://github.com/collin80/due_can/blob/master/due_can.cpp

but I don’t think that is what we are talking about.

#4

It both is and isn’t what you’re talking about. One way to do auto baud detection is to set the interface to listen only with a guessed baud rate. If that’s the right speed and there is traffic then you’ll get some traffic and know it worked. If it doesn’t work then you try another baud rate. Being in listen only mode means that you won’t break the bus if you’re on the wrong speed. All that will happen is that it won’t work. So, the method would be to generate a list of candidate baud rates in descending order of likelihood and then try each one in turn until traffic shows up. Obviously you can only do this on a live bus with traffic.

#5

Right on! That makes sense, thanks Collin. I think this would be a cool feature. Seems like every time we encounter a new car, we spend too much time figuring this part out.

I know the TJA1051 transceiver itself has a “silent” mode as well. From the datasheet:

7.1.2 Silent mode
A HIGH level on pin S selects Silent mode. In Silent mode the transmitter is disabled,
releasing the bus pins to recessive state. All other IC functions, including the receiver,
continue to operate as in Normal mode. Silent mode can be used to prevent a faulty CAN
controller from disrupting all network communications.

#6

I actually planned to tackle this sort of thing but I am new to programming an Arduino so I am working through the libraries now to under stand them. Figured I would start with the Due_Can Library but not sure what the “mailboxes” stuff is for.

Also wondering if we shouldn’t start a slack for this stuff too… Might be quicker to get information that way… Dunno.

Rodney

#7

Just heard that Tim over at Grimm created a autobaud for this already but hasn’t been pushed to the mainline code yet.

I am in progress of reading and digesting the current library now. I will be evaluating it to see what I want to do next. I have some hunches on the code but want to defer comment until I understand the code and how it is utilized.

Rodney

#8

Hehe, interesting story about Grimm. Grand Rapids, Michigan where I am from has an Embedded Developers meet up every other month. Quite often I do presentations at the meet up. Anyway, one of the meetup topics was security and people from Grimm came to do a presentation (I don’t remember the exact topic). Anyway, midway through the presentation the guy said that he realized just that day that he had been using a CAN library written by one of the other presenters - me. So, yeah, Grimm is aware of my work with CAN libraries and they’ve got a location right here in Grand Rapids. So, it’s kind of a small world. If nobody else comes up with an autobaud routine I can easily do it. It just hasn’t been high on the radar.

Edit: I just realized that redheadedrod probably already knew most of that. Perhaps its news to everyone else though. :wink:

#9

I interned with Matt from Grimm last summer. Him and I still talk occasionally. I don’t know that anyone else lives in the immediate area that works for Grimm but Matthew does live in the area and is pretty involved in the local security community.

#10

Well, I just added auto baud support to mainline due_can so everyone can use it now. There’s a new example sketch that shows how to use it but really it is pretty simple. I never did see TIm’s implementation but well, you snooze, you lose. Chances are it was similar anyway - there’s only so many ways to do auto baud.

Patron Program: Dollars for Devs
#11

I will hopefully be getting a copy of Tim’s code after Defcon and will look into it.