3

I would like to have Arduino operating in a CAN network. Does the software that provides OSI model network layer exist for Arduino? I would imagine detecting the HI/LOW levels with GPIO/ADC and sending the signal to the network with DAC. It would be nice to have that without any extra hardware attached. I don't mind to have a terminating resistor required by the CAN network though.

By Arduino I mean any of them. My intention is to keep the development environmen.

If such a software does not exist, is there any technical obstacle for that, like limited flash size (again, I don't mean particular board with certain Atmega chip).

Nikita Vorontsov
  • 194
  • 2
  • 15
  • 1
    You should ask yourself if you have any idea what a CAN bus is and what it requires, before coming up with ideas like this... It simply doesn't make any sense whatsoever to do this in software. The first MCU with CAN controller on-chip was released at least 15 years ago. There are even MCUs with controller+tranceiver on-chip, such as [LPC11C22](http://www.nxp.com/documents/data_sheet/LPC11CX2_CX4.pdf) (ARM Cortex M0). – Lundin Feb 28 '14 at 14:59

3 Answers3

6

You can write a bit banging CAN driver, but it has many limitations.
First it's the timeing, it's hard to achieve the bit timing and also the arbitration.

You will be able to get 10kb or perhaps even 50kb but that consumes a huge amount of your cpu time.
And the code itself is a pain.
You have to calculate the CRC on the fly (easy) but to implement the collision detection and all the timing parameters is not easy.

Once, I done this for a company, but it was a realy bad idea.

Better buy a chip for 1 Euro and be happy.

jeb
  • 78,592
  • 17
  • 171
  • 225
  • Thanks. That is what I was thinking of - it is too affordable to get real CAN controller on board and have interrupts and serial communication for data exchange with main controller (ATMega, in case of Arduino). That is probably the reason no one is doing that. What was the platform you implemented it for, may I ask? – Nikita Vorontsov Feb 28 '14 at 10:54
  • +1 absolutely. I would not go near CAN without a hardware controller. – Martin James Feb 28 '14 at 11:28
  • 2
    @NikitaVorontsov I implemented it for a msp430 (Texas Instruments) – jeb Feb 28 '14 at 12:12
  • 1
    @jeb But... why... Your company has too much money and too many developers? – Lundin Feb 28 '14 at 15:03
  • 2
    @Lundin It was a stupid idea, I couldn't believe it when I began to work there. And yes, it cost much money and then ... they add a CAN chip – jeb Feb 28 '14 at 16:06
3

There are several CAN Bus Shield boards available (e.g: this, and this), and that would be a far better solution. It is not just a matter of the controller chip, the bus interface, line drivers, and power all need to be considered. If you have the resources and skills you can of course create your own board or bread-board for less.

Even if you bit-bang it via GPIO you would need some hardware mods I believe to handle bus contention detection, and it would be very slow and may not interoperate well with "real" CAN controllers on the bus.

If your aim is to communicate between devices of your own design rather than off-the shelf CAN devices, then you don't need CAN for that, and something proprietary will suffice, and a UART will perform faster that a bit-banged CAN implementation.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • As I mentioned in my question, I was looking for something existing (I didn't intend to develop it myself). Also, about the hardware needed - I mentioned I am not against couple of passive components. But having a fully-featured CAN controller attached - is different. In this case what you suggest makes more sense. Thanks for your answer anyway . – Nikita Vorontsov Feb 28 '14 at 15:38
2

I don't think, that such software exists. CAN bus is more complex, than for example I2C. Basically you would have to implement functionality of both CAN controller and CAN transceiver. See this thread for more details (in German).

Alternatively you could use one of the CAN shields. Another option were to use BeagleBone with suitable CAN cape.

Also take a look at AVR-CAN.

yegorich
  • 4,653
  • 3
  • 31
  • 37
  • 1
    The original idea was to get CAN on chips without CAN controller implemented but GPIOs capable of CAN (at least low speed). So, the accepted answer confirms my suspicion that it simply makes no sense, given the low-cost hardware available. Thanks for all the links anyways. – Nikita Vorontsov Jan 05 '15 at 13:29