CAN Bus module - Controller Area Network with general purpose avr. Possible or not?

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One of my first projects i'm working on to learn programming on AVR is communicating with the CAN Bus available in my own car.

I see a lot of tutorials doing that but with a CANBUS Module with MCP2515 Chip! 

 

I know the module is like a specific programmed microcontroller for can communication. 

What if i wish to make this canbus module with one of my atmega328's i have here, would that be possible? If not, why would i need the MCP2515?

 

Link to the module:
http://www.dx.com/nl/p/mcp2515-c...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wouldn't say bit bashing CAN is impossible but considering no one has done it before, then I'd say it is difficult. Even the ELM3 module uses a micro with CAN hardware. So choose a micro with CAN hardware or use an external CAN chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But why is that? What is so special about the Can hardware that makes it difficult to make it yourself with something else?
Would it be possible with an FPGA chip then? << (Even if it wouldn't make it cheaper)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you REALLY want to know, then read the CAN spec from Bosch then decide if it can be done.  I think you'll find that the poor AVR runs out of time when bit bashing a 1 Mbit data stream whilst detecting collisions. Something like a XMOS chip can probably do it in software.

Sure it's possible in a FPGA - you only need to Google to figure that one out. I Googled fpga can controller

There's also many micros with CAN controllers built in and examples for what you want to do.

Last Edited: Wed. Jul 26, 2017 - 11:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zerco wrote:

But why is that? What is so special about the Can hardware that makes it difficult to make it yourself with something else?
Would it be possible with an FPGA chip then? << (Even if it wouldn't make it cheaper)

Sure, it's possible on FPGA.

 

The MCP2515 is low cost, why not simply use that, given this is "One of your first projects you're working on to learn programming on AVR"

 

FWIR, CAN has critical bit timing, and CRC, so whilst you could use an AVR Bit-Banged to cobble a 'mostly works' design, the MCU is then so loaded up and critical, you have time for nothing else.

For very low cost nodes, LIN bus seems to have taken over.

 

A quick Digikey 'search within results' for CAN, finds parts from ST,Renesas,Microchip,NXP,Cypress,Nuvoton, SiLabs and some of the Microchip CAN ones have AVR part codes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who-me wrote:

zerco wrote:

But why is that? What is so special about the Can hardware that makes it difficult to make it yourself with something else?
Would it be possible with an FPGA chip then? << (Even if it wouldn't make it cheaper)

Sure, it's possible on FPGA.

 

The MCP2515 is low cost, why not simply use that, given this is "One of your first projects you're working on to learn programming on AVR"

 

 

I Already ordered two CAN Modules, i'm waiting for them to arrive.

This question is only for understanding. I actually have a learn a lot about avr programming or embedded programming in general and im in the very early stage

 

http://www.bosch-semiconductors....

According to this you have to pay fees when you manufacture your own CAN. Ofcourse only when used professionally

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zerco wrote:
One of my first projects i'm working on to learn programming on AVR

This sounds rather ambitious as a first project for someone only just learning programming!

 

surprise

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sniffing a CAN bus is relively easy, and uC can do it.

But when sending CAN messages you have to check for collisions & back off ass fast as possible when the bus is taken over by a device with "higher priority".

 

This dictates a 100 % CPU utilisation if you do it all in software or it would require hardware to detect a difference between the data bits being send and the data bits on the bus.

 

Here is a blog of a guy who has tried this, but he later decided to use "real" CAN hardware.

http://omzlo.com/articles/how-th...

 

But it surely will be a learning experience if you build this.

 

Sidenote:

I've always wondered if the brakes (ABS, ignition, etc) stop working if you short out the can bus in a car.

There probably is some bridge between a "critica" can bus part and a "utility" part.

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
There probably is some bridge between a "critica" can bus part and a "utility" part.

I thought there were separate CAN busses ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I would suggest you check out the Arduino Uno and any of the many CANbus shields available.

Lots of CAR can bus sniffer projects with a quick google search using these.

 

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
This sounds rather ambitious
+100

 

V-USB is a bit like the idea here. That is a bit-bang emulation of USB on an AVR - it takes almost all the horsepower an AVR has to achieve it. It's a very clever trick and it took a very skilled engineer to come up with a working solution in the first place.

 

As you are talking about  328 why not simply get an Arduino and put a CAN shield on top - job done.

 

Alternatively why not simply use one of:

 

One of these...

 

 

I know it's true that if I wanted to drive from NY to LA I could get a solid block of steel (perhaps aluminum?) and hone a cylinder block / cylinder head from it and a bunch of pistons. With more steel I could construct a chassis and if I bought a rubber tree I guess I could eventually garner sufficient rubber to make a set of tyres? But, to be honest, I think I might just go to a local car dealer and buy a car. The joy of travelling from NY to LA is enjoying several thousand miles of scenery, not constructing a car from scratch first!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I rather not ask, but does someone has a reference to the Bosch CAN 2.2 Specification? I can't find it on google, only the CAN 2.0 specification which dates from 1991 (http://esd.cs.ucr.edu/webres/can...

Or any detailed book on the CAN Bus? 

 

My MCP2515 Chip is on its way! :)

Last Edited: Fri. Jul 28, 2017 - 12:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

I know it's true that if I wanted to drive from NY to LA I could get a solid block of steel (perhaps aluminum?) and hone a cylinder block / cylinder head from it and a bunch of pistons. With more steel I could construct a chassis and if I bought a rubber tree I guess I could eventually garner sufficient rubber to make a set of tyres? But, to be honest, I think I might just go to a local car dealer and buy a car. The joy of travelling from NY to LA is enjoying several thousand miles of scenery, not constructing a car from scratch first!

 

haha

Sometimes constructing the car from scratch is a journey on itself! In this case its for learning

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just typed "CAN Specification" into Google. Top hit was:

 

http://esd.cs.ucr.edu/webres/can...

 

 

Isn't that what you want?

 

(actually that is the same as your link - so yes - why is it important that it dates from 1991 - CAN has been around for a LONG time!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CAN 2.0 isn't outdated since 1991? So version 2.2 doesn't differ much from version 2.0 ? If so then i indeed have what i'm looking for

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Recent" extensions to CAN have generally been more about the protocol than the sigalling. Like more bits in the CAN frame ID and so on.

 

BTW make the most of CAN while you can, it is slowly but surely being replaced in modern vehicles (I work on the design of car electronics - specifically vision processing control systems but among that we use CAN, Flexray and other messaging network systems in the car).
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

"Recent" extensions to CAN have generally been more about the protocol than the sigalling. Like more bits in the CAN frame ID and so on.

 

BTW make the most of CAN while you can, it is slowly but surely being replaced in modern vehicles (I work on the design of car electronics - specifically vision processing control systems but among that we use CAN, Flexray and other messaging network systems in the car).
 

 

Thanks, i've printed some documentation on canbus and flexray. Lets see if i understand anything from the documentation

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zerco wrote:

CAN 2.0 isn't outdated since 1991? So version 2.2 doesn't differ much from version 2.0 ? If so then i indeed have what i'm looking for

 

There is a new faster CAN spec out, CAN FD, which complicates things even more, and makes SW-banging harder...

http://gridconnect.com/blog/gene...

 

MCU support for CAN FD http://www.microchip.com/design-...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And also for you:

Go get a USD 5 logic analyser.

Search Ali / Ebay for "24M 8CH".

And run it with Sigrok / Pulseview.

http://www.sigrok.org

Pulseview (GUI wrapped around sigrok) also has a decoder for the CAN bus.

So you will  instantly add meaning to all states & transitions on the can bus and you can scroll through it on your big PC screen.

If you make any errors while sending CAN messages they will (probably) get an instant big red Flag in Pulseview.

(Logic analysers work very well with a PC interface (unlike oscilloscopes, which are better of with a box with buttons on it).

Really, get some LA's.

Note: General Cypress CY7C86... boards can be used with upto 16 channels in sigrok, but they do not have I/O buffering / protection.

the "24M 8CH" comes with 8 channels 150 R series resistors and a box to keep the dirt out.

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Sat. Jul 29, 2017 - 12:47 PM