CAN bus

Hardware inside and outside of the ECU
Post Reply
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

CAN bus

Post by AndreyB »

I have a 2003 Mini Cooper I can use for CAN bus tests. Right now that's all I have or know about the CAN bus.

Where do I buy an OBD-II connector to connect to the CAN board physically? Do I need any electronics between the OBD-II connector CAN pins the discovery board? Any info on the hardware side of this would be appreciated.

The software side of this would be handled within https://sourceforge.net/p/rusefi/tickets/21/
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: CAN bus

Post by kb1gtt »

CAN bus is often used for OBDII, however CAN bus is far more. I might encourage CTU originally drafted by EssEss. I have hacked a setup with off the shelf components, for not much $, I think it was less than $50. We had this passing CAN traffic to and from an MCU. We used it as a serial interface for TS. Basically TS would connect to a USB port FTDI chip that registered as a COM port, then the serial stream was sent to an LPC ARM, which then put it on the CAN bus. The MCU was decoding CAN as a serial stream, which allowed TS table updates via TS, with TS having no knowledge that it was over CAN. If CTU is assembled I seem to recall it would cost less than $10 -ish in low QTY. CTU gets you USB to TTL 232, then CAN. So if you want to use it as an interface for an MCU, it's easy to trim it asn include it in your own design and such. Of course I did CTU in KICAD.

CTU found here. http://code.google.com/p/daecu/source/browse/#svn%2FHardware%2Ftrunk%2FKICAD_Project_CTU If there is interest, I can probably go find the code red code to function as a reference.

I would suggest avoiding the OBDII complications now, as that's not really value add. CAN for diag can be far more than what you get over OBDII, and far simpler. I see value in using CAN to steam data to gauges, or to allow table updates, perhaps firmware updates, ect. OBDII doesn't allow most of that and the refresh rates for gauges is far to slow.
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: CAN bus

Post by AndreyB »

OBDII connector here is only for the purposes of the physical connection to the bus.

So where do I get the command codes for a specific vehicle?
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
jedediah_frey
contributor
contributor
Posts: 51
Joined: Tue Nov 05, 2013 1:43 pm

Re: CAN bus

Post by jedediah_frey »

russian wrote:Where do I buy an OBD-II connector to connect to the CAN board physically? Do I need any electronics between the OBD-II connector CAN pins the discovery board? Any info on the hardware side of this would be appreciated.
You will likely need a level shifter. I'm not sure what voltage the CAN bus operates at (if you have a scope you could easily see)

As far as where to get the connectors: anywhere.

http://dx.com/p/01180019-16pin-car-diagnostic-plug-obd2-connector-bluetooth-elm327-assembly-shell-white-216952?tc=USD&gclid=CPDNrpH49roCFchaMgodL0sASQ

http://allobd.com/proddetail.asp?prod=ST-144601&cat=35
Last edited by jedediah_frey on Thu Nov 21, 2013 10:45 pm, edited 1 time in total.
jedediah_frey
contributor
contributor
Posts: 51
Joined: Tue Nov 05, 2013 1:43 pm

Re: CAN bus

Post by jedediah_frey »

So where do I get the command codes for a specific vehicle?
You listen :)

http://www.dgtech.com/images/primer.pdf

There are some standard PGN/SPNs and every device on the network will have its own ID but beyond that it's all up to the manufacturer. You just need to get into the car and start sniffing messages and see what is there.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: CAN bus

Post by kb1gtt »

For those that are new to CAN bus, I thought a picture might help

Image

Sorry I broke my funny bone when I was a kid, it never healed correctly :)
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: CAN bus

Post by AndreyB »

kb1gtt wrote:I thought a picture might help
This picture is a shameless off-topic! On the contrary, here is some CAN info specific to the Mini Cooper in question:

"Another little detail has purely something to do with the design of the mini. It is about the exhaust pipe. (One on the cooper, two on the S). The story goes, (and I do not quite know where I got it from), that the design team at BMW was about to show the full size model of the car in a preliminary presentation. Everything seemed pretty much designed. Except for the exhaust pipe. It was just this typically shaped piece of pipe. It was late at night, (which makes the story sound true) and one of the designers just had a beer (true?, maybe a soda)... And so she just cut of the top of the can, spray painted it silver and stuck it onto the then exhaust pipe. Just for fun. The designer in Chief liked the look, as did everybody else, and so all minis now have exhausts that look like a bottom of a Beer-can. True story?... I hope it is. I really hope it is. Maybe you know more than me?, maybe you can find out. Call BMW, ask them."
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
User avatar
mobyfab
Posts: 139
Joined: Tue Oct 29, 2013 10:09 am
Location: Versailles, France

Re: CAN bus

Post by mobyfab »

You can get an OBD2 connector on site like ebay.

You will need a CAN transceiver such as the MCP2551 or the newer MCP2562 (for 3.3v compat) between the CAN pins of the STM32 and the bus lines.
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: CAN bus

Post by kb1gtt »

A bit more OT, this is a nice low cost CAN interface board. http://www.wvshare.com/product/SN65HVD230-CAN-Board.htm I've got one so I could even help play with it.
Welcome to the friendlier side of internet crazy :)
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: CAN bus

Post by AndreyB »

kb1gtt wrote:A bit more OT, this is a nice low cost CAN interface board. http://www.wvshare.com/product/SN65HVD230-CAN-Board.htm I've got one so I could even help play with it.
That's exactly what I need right now, I've placed an order! If it works we will need to make our own PCB module :)

Order place: Nov 24, 2013
Order paid: Nov 25, 2013
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
jedediah_frey
contributor
contributor
Posts: 51
Joined: Tue Nov 05, 2013 1:43 pm

Re: CAN bus

Post by jedediah_frey »

Keep in mind that you might have 2 if not 3 CAN busses.

The drivetrain will likely be at 500 kbit or 1 Mbit. While there is another one that runs at 250 kbit that controls windows, etc. This is how VW is set up.

From this it looks like the MiniCooper might only have 1 with most things being on K-bus.

https://www.defcon.org/images/defcon-21/dc-21-presentations/Staggs/DEFCON-21-Staggs-How-to-Hack-Your-Mini-Cooper-WP.pdf

https://www.defcon.org/images/defcon-21/dc-21-presentations/Staggs/DEFCON-21-Staggs-How-to-Hack-Your-Mini-Cooper-Updated.pdf

http://bobodyne.com/web-docs/robots/MINI/CAN/MINI_CAN.pdf
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: CAN bus

Post by puff »

Am I right that CAN bus pins are PB6 and PB12?
What else is needed to start receiving any messages from the certain engine config? (Rover8)
In TS config CAN write is enabled.
Should it be sending out any messages even at 0 RPM?
User avatar
kb1gtt
contributor
contributor
Posts: 3758
Joined: Tue Sep 10, 2013 1:42 am
Location: ME of USA

Re: CAN bus

Post by kb1gtt »

For default rusEFI software, yes PB6 and PB12. However other options are possible.

Do you know your CAN messages from the target? There are ID's that you'll need at a min, for example, engine to transmission messages will have their own ID's, while engine to dash messages will have a lower priority ID.
Welcome to the friendlier side of internet crazy :)
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: CAN bus

Post by puff »

At the moment I am compiling the code to send out any CAN messages just to uart. Ideally that would be RPM and CLT info. (I seem to have an android app for that, so I'd like to decode those CAN messages on my micro controller, and then send it via uart&bluetooth to android).

As I am not using any car-specific hardware, I don't care what message formats that would be - Mazda, VAG, or BMW.

For now the goal is to see any CAN messages from my Rover config.

So far I can't understand what makes all this magic. E.g. there is static void canMazdaRX8(void) in can_hw.cpp, but I can't figure out where in code this procedure is called…

In January I'll probably order those ADS1118 and thermocouples to play with them - hopefully in the end there'll be a device sending temperature values over CAN.
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: CAN bus

Post by AndreyB »

puff wrote: there is static void canMazdaRX8(void) in can_hw.cpp, but I can't figure out where in code this procedure is called…
this sounds pretty worrisome, you need to fix your IDE or simply use full-text search

Here is a section from the bottom of dodge_neon.cpp:

Code: Select all

	engineConfiguration->isCanEnabled = true;
	boardConfiguration->canTxPin = GPIOB_6;
	boardConfiguration->canRxPin = GPIOB_12;
	engineConfiguration->canWriteEnabled = true;
	engineConfiguration->canReadEnabled = false;
	engineConfiguration->canNbcType = CAN_BUS_NBC_BMW;
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: CAN bus

Post by puff »

yep. thanks. my mistake - i was looking for some external calls, but they are called from the same file. (i mean that 'switch-case' structure)
seems like I need to add these lines to rover_v8.cpp and recompile the code? or was it something special about that neon thing that some of its properties are inherited by other engine files?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: CAN bus

Post by AndreyB »

Yes, kind of.

Please note that "there is static void" and "i was looking for some external calls" is a contradiction. In C, static means that an entity is ONLY available from the same file and is not exported for external linking.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
puff
contributor
contributor
Posts: 2961
Joined: Mon Nov 11, 2013 11:28 am
Location: Moskau

Re: CAN bus

Post by puff »

Please note that "there is static void" and "i was looking for some external calls" is a contradiction. In C, static means that an entity is ONLY available from the same file and is not exported for external linking.
yep. I am an old man. I studied long time ago. Never studied C by the way… Sorry.

There's something wrong probably: I added those lines to my rover config file. Recompiled the code. Flashed it. Connected logic analyzer to pb6&pb12. Restarted the board and saw nothing in Logic. I assumed it should be at least trying to send anything on those ports? Or should I connect the transceiver and the other device as well?

Could anyone please confirm that there should be signals on pb6 and pb12 without the transceiver connected to it?
User avatar
AndreyB
Site Admin
Posts: 14292
Joined: Wed Aug 28, 2013 1:28 am
Location: Jersey City
Github Username: rusefillc
Slack: Andrey B

Re: CAN bus

Post by AndreyB »

The best approach to this would be figuring out what of the CAN options are not in TunerStudio .ini yet, and adding the missing stuff if anything is missing.
Very limited telepathic abilities - please post logs & tunes where appropriate - http://rusefi.com/s/questions

Always looking for C/C++/Java/PHP developers! Please help us see https://rusefi.com/s/howtocontribute
Post Reply