CAN controller


566 posts   Page 2 of 23   1, 2, 3, 4, 5 ... 23
by leszek » Sat Jul 21, 2012 8:23 am
Have already done a CAN proto board based on the Microchip MCP2515.

I have used:
- Protoboard from http://www.bitbang.co.uk
- CAN MCP2515 3.3V board from http://www.mikroe.com
- TTL UART -> USB from http://www.ftdichip.com

All parts already assembled and working. Currently I am doing some kernel patches in order to get the CAN fully optimized.The FTDI is used to get access of the serial console, that is really needed for kernel debugging.

Some other photos are already on my flickr: http://www.flickr.com/photos/leszekp/
Attachments
CAN_Board.jpg
CAN_Board.jpg (58.38 KiB) Viewed 5352 times
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by kiwi64ajs » Mon Jul 23, 2012 7:14 am
leszek wrote:Have already done a CAN proto board based on the Microchip MCP2515.
... Currently I am doing some kernel patches in order to get the CAN fully optimized.

That sounds promising. Are you able to share the config file changes to define the SPI and hardware interrupt line definitions for the MCP2515? There are hints about what needs to go where for similar platforms but not specifically for the ARM family used on the RPi.

I've got one of these CAN Interfaces: http://www.futurlec.com/Mini_CAN_Board.shtml

Looking forward to getting this going...

Regards
Alex Shepherd
Posts: 5
Joined: Thu Nov 03, 2011 9:10 pm
by leszek » Mon Jul 23, 2012 8:38 am
I am already able to talk with the MCP2515 over SPI, however in the pooling mode so far. Now I am doing optimization changes in the CAN kernel socket driver in order to get communications through it. The next step will be to use interrupts, however possibly this will require more effort (I have already done it for TI Sitara, but for Broadcom is looks that I have to start from scratch).

The CAN Miniboard board that you have proposed seems to be okay. Looking on the pictures, they are using TI SN65HVD232 CAN Transceiver that is 3.3V level and there no LDO 1117 (3.3V) placed so it seems that the board can be only for 3.3V I/O levels used.

Regards,
Leszek
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by hjoertel » Mon Jul 23, 2012 8:49 pm
Hello,

I have the following adapter http://www.avrcard.com/products/can_adapter.htm available for tests.
Can please one of you check if I can connect the Raspberry SPI pins directly to this board
or do I need some level shift between these two in order to connect the 5V powered VAN interface with the Raspberry.
I have maintained the MCP2515 can4linux driver and hope I will be able to port it to the Raspberry,
assuming a have a working hardware.
Let me know what you think if this will be possible.
Regards
Heinz
Posts: 6
Joined: Mon Jul 23, 2012 8:38 pm
by leszek » Tue Jul 24, 2012 9:02 am
Heinz,

Your board: http://www.avrcard.com/products/can_adapter.htm can't be used directly due to I/Os that are 5V level and RPi I/Os are NOT 5V tolerant. As you suggested, a level shifter possibly can be used, but driving SPI at 10MHz with shifting could generate other unexpected issues (e.g. due to timings issues).

My suggestions would be to use a “native” 3.3V CAN Board. You could use one of:
- proposed by Alex: http://www.futurlec.com/Mini_CAN_Board.shtml
- or proposed by me: http://www.mikroe.com/eng/categories/vi ... ck-boards/

All the boards (inclusive your) are using same CAN Controller - MCP2515, so the software will be the same, but the CAN Timings has to adjusted due to another onboard oscillator.

The board from www.mikroe.com I have already got running over SPI.

Regards,
Leszek
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by kiwi64ajs » Tue Jul 24, 2012 11:07 am
leszek wrote:I am already able to talk with the MCP2515 over SPI, however in the pooling mode so far. Now I am doing optimization changes in the CAN kernel socket driver in order to get communications through it. The next step will be to use interrupts, however possibly this will require more effort (I have already done it for TI Sitara, but for Broadcom is looks that I have to start from scratch).

Well, following the links from Chris Boot's blog here: http://www.bootc.net/projects/raspberry-pi-kernel/ right through to the commit logs on the git repo that he is using here: https://github.com/bootc/linux/commits/rpi-3.2.23

There are a couple of commits that might give some clues:
https://github.com/bootc/linux/commit/5 ... 1be8cc7c37
https://github.com/bootc/linux/commit/2 ... 9eb6d555e7

Or perhaps the clue might be just to ask Chris as he seems to be "doing stuff" with interrupts...
It's probably something really simply once you know where to apply the missing glue code...

HTH
Alex Shepherd
Posts: 5
Joined: Thu Nov 03, 2011 9:10 pm
by leszek » Tue Jul 24, 2012 12:16 pm
Thanks Alex,

already knew those links. The problem is, that all the work has to be done inside the CAN Driver, including interrupting the MCP2515 itself by GPIO in order to get maximum performance.

Actually will do some investigations on it and will keep informed.

Regards,
Leszek
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by Wolfram23 » Tue Jul 24, 2012 3:20 pm
Hmm... I'm a newbie but I think you guys are over thinking this. An STN1110 chip is $10 and interfaces with the ECU, and supports all OBDII protocols. I need ISO for my car, as CAN wasn't implemented yet (2002 Acura), but the STN is good for all of them. It also accepts up to 5V input, but is meant for 3V so it should play nice.
http://www.sparkfun.com/datasheets/Widg ... 110-ds.pdf

Anyway, from there you need to know how to wire it up. Well, plenty of people have done this with Arduinos (OBDuino), so why not copy that? Check out these pages:
http://code.google.com/p/opengauge/wiki/OBDuinoDiagram
http://blog.workingsi.com/2010/10/resea ... rface.html
http://wiki.tinyclr.com/index.php?title ... D_-_ELM327

FYI, ELM327 and STN1110 are basically identical, but the STN is cheaper and faster. However, they both can be communicated with using "AT" commands, and it handles the translations to bit code. You can read about the AT commands here:
http://elmelectronics.com/ELM327/AT_Commands.pdf

With the diagrams and such, you need only a cheap breadboard and a few resistors, transistors, w/e, and can easily build the board yourself instead of shelling out for the Sparkfun one.

If this helps make any progress I'd love to hear about it. Definitely want to make an OBDII interface with a 16x2 LED display just like the OBDuino, running off GPIO.
Posts: 73
Joined: Thu Jul 19, 2012 6:50 pm
by leszek » Tue Jul 24, 2012 4:57 pm
Wolfram23,

we are talking about two different thinks.

ELM327 (and similar chips) are just Microchip PIC18Fxxxx with programmed firmware. That firmware doesn't give option to use CAN on full load at 1MBit/s but much, much slower and that chip is supposed to do "some basic" OBD diagnostics only.

The MCP2515 is a full CAN Controller with all features like buffering or filtering. Using it, I am able to build a fully independent CAN Node, Host or Gateway that runs on full speed.

I have already successfully tested MCP2515 on BeagleBone (some photos are already on my flickr: http://www.flickr.com/photos/leszekp/) and I am already able to communicate with an ECU by using CAN CCP at 1Mbit/s and 90% busload. I am also able to do ECU flashing (CAN UDS) at 500 Kbit/s and pretty much at full busload.

I would like to do same think an RPi. The only think is just to create a fully optimized CAN Driver, rest is already same (e.g. socket communications).

Regards,
Leszek
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by hjoertel » Tue Jul 24, 2012 6:49 pm
leszek wrote:Heinz,
..........
My suggestions would be to use a “native” 3.3V CAN Board. You could use one of:
- proposed by Alex: http://www.futurlec.com/Mini_CAN_Board.shtml
- or proposed by me: http://www.mikroe.com/eng/categories/vi ... ck-boards/
.......
Regards,
Leszek


Hello Leszk,
can you please confirm that http://www.mikroe.com is delivering to Germany.
How did you get your 'CAN SPI click 3.3V' ?
Regards
Heinz
Posts: 6
Joined: Mon Jul 23, 2012 8:38 pm
by leszek » Wed Jul 25, 2012 5:26 am
Heinz,

I bought it on http://de.mouser.com together with same other parts that I needed for another projects.

As soon as you place order over 75 EUR, the shipping (FedEx) and customs (import USA) are inclusive and you will get it very quickly (typically two days to Munich, Germany).

Regards,
Leszek
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by hjoertel » Wed Jul 25, 2012 10:47 am
Thanks,
Mouser has only a newer module on stock, slightly more expensive.
http://de.mouser.com/ProductDetail/mikr ... w51ZgRA%3d

Manual is there:
http://www.mouser.com/ds/0/mikroElektro ... 0-7237.pdf
It lacks information about the voltage supply (and more :-( )
The used transceiver is MCP2551, has an Operating Voltage Range (V) 4.5 to 5.5 :-(

It seems that in the moment I have no chance to get a working CAN Hardware for the Raspberry.
http://www.futurlec.com/Mini_CAN_Board.shtml
The
http://www.futurlec.com/Mini_CAN_Board.shtml which you heve mentioned too,
also has a "Optional Microchip MCP2551 Mounting Socket"
Or is there a pin compatible 3.3 V transceiver ?

Regards
Heinz
Posts: 6
Joined: Mon Jul 23, 2012 8:38 pm
by hjoertel » Wed Jul 25, 2012 11:13 am
Leszek,
I just looked at ordering direct at MikroElektronika.
Shipping alone to Germany is already $25. That's too much for a small board for $21.
Belgrad - Halle(Saale) is about 1000 km.

Regards
Heinz
Posts: 6
Joined: Mon Jul 23, 2012 8:38 pm
by leszek » Wed Jul 25, 2012 4:56 pm
Heinz,

Mouser has the module - just search for "can board 3.3v" and you will found it :)

http://de.mouser.com/Search/Refine.aspx ... ewSearch=1

Cost 17.33 EUR + MwSt.

Ordering directly from Mikroelektronika is very expensive, because they are not in EU and don't even a local warehouse here in Germany. Therefore I doing "combined" orders from Mouser or DigiKey.

Possibly I will make a small order from Mouser within next 4 - 5 weeks. If you would like to, I could additionally order one board for you and resend to you by Deutsche Post or DHL. Just send me a private message if you would like to have one.

The CAN Miniboard - http://www.futurlec.com/Mini_CAN_Board.shtml I have already checked. Looking on the pictures, they are using TI SN65HVD232 CAN Transceiver that is 3.3V level and there no LDO 1117 (3.3V) placed so it seems that the board can be only for 3.3V I/O levels used. In other words you just need that board.

Regards,
Leszek
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by hjoertel » Wed Jul 25, 2012 8:02 pm
Leszek,
Thanks for the offer.
I'm just thinking about putting these two chips on a small breadboard.
If this doesn't work - I'll come back.

Heinz
Posts: 6
Joined: Mon Jul 23, 2012 8:38 pm
by kiwi64ajs » Wed Jul 25, 2012 8:38 pm
hjoertel wrote:Leszek,
I'm just thinking about putting these two chips on a small breadboard.
If this doesn't work - I'll come back. Heinz


What about trying one of these:
http://www.futurlec.com/Mini_CAN_Board.shtml

The board was $US 12.90, freight to New Zealand $US7

I also brought some DIP chips while I was at it in case I make a plate using veroboard assuming it all works...

Alex
Posts: 5
Joined: Thu Nov 03, 2011 9:10 pm
by hjoertel » Thu Jul 26, 2012 9:24 pm
I'm going to use the 5 V board I have and exchanging the NXP transceiver with a 3.3V TI one

Heinz
Posts: 6
Joined: Mon Jul 23, 2012 8:38 pm
by owlmaker » Mon Jul 30, 2012 8:59 pm
Hello,

for those who are interested in the 'CAN SPI click 3.3V' board and who are living in Europe: I just found it available from tigal.com, who ship from Austria.

cheers,
Ulrich
Posts: 1
Joined: Thu Jul 12, 2012 12:53 pm
Location: germany
by leszek » Tue Jul 31, 2012 5:36 pm
Yes, they have. But shipping to Germany for that small board is not cheap (9.00 EUR).

I always making orders from Mouser or Digikey, they are really fast, they have almost everything on stock and they offers free shipping on orders over 65.00 EUR.
User avatar
Posts: 8
Joined: Sat Jul 21, 2012 7:58 am
Location: Munich, Germany
by jmg123 » Mon Aug 06, 2012 9:27 pm
leszek wrote:Wolfram23,


I have already successfully tested MCP2515 on BeagleBone (some photos are already on my flickr: http://www.flickr.com/photos/leszekp/) and I am already able to communicate with an ECU by using CAN CCP at 1Mbit/s and 90% busload. I am also able to do ECU flashing (CAN UDS) at 500 Kbit/s and pretty much at full busload.

Regards,
Leszek



90% Bus load - ouch :shock:
Posts: 21
Joined: Thu Sep 22, 2011 6:39 pm
by bertr2d2 » Thu Aug 09, 2012 6:42 am
This might be of your interest

http://lnxpps.de/rpie

MCP2515 + MCP2551 with GPIO25 (IRQ110) interrupt - working

Code: Select all
[  394.151290] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[  465.325599] can: controller area network core (rev 20090105 abi 8)
[  465.325968] NET: Registered protocol family 29
[  523.007604] CAN device driver interface
[  560.310129] can: raw protocol (rev 20090105)
[  565.070666] can: broadcast manager protocol (rev 20090105 t)
[  593.259813] mcp251x spi0.0: CANSTAT 0x80 CANCTRL 0x07
[  593.266881] mcp251x spi0.0: probed
[  638.710821] mcp251x spi0.0: CNF: 0x03 0xb5 0x01

root@raspberrypi ~ # cansend can0 123#deadbeef

root@raspberrypi ~src/linux-3.1.9+ (git)-[rpi-patches] # candump any,0:0,#FFFFFFFF
  can0  123  [4] DE AD BE EF
  can0  123  [4] DE AD BE EF

root@raspberrypi ~src/linux-3.1.9+ (git)-[rpi-patches] # cat /proc/interrupts
           CPU0       
...
110:          2      GPIO  mcp251x
Err:          0
Posts: 86
Joined: Wed Aug 08, 2012 10:12 pm
by AxelB » Fri Aug 10, 2012 12:33 pm
This might be of your interest

http://lnxpps.de/rpie

MCP2515 + MCP2551 with GPIO25 (IRQ110) interrupt - working

I have a very similar setup working. Main difference is a different transceiver (SN65HVD230), which is supplied with 3.3V.
I did the following changes to the board configuration file:
Code: Select all
diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
index b814a35..887afe0 100644
--- a/arch/arm/mach-bcm2708/bcm2708.c
+++ b/arch/arm/mach-bcm2708/bcm2708.c
@@ -53,6 +53,10 @@
 #include <mach/vcio.h>
 #include <mach/system.h>
 
+#include <linux/can/platform/mcp251x.h>
+#include <linux/gpio.h>
+#include <linux/irq.h>
+
 #include "bcm2708.h"
 #include "armctrl.h"
 #include "clock.h"
@@ -493,6 +497,15 @@ static struct resource bcm2708_spi_resources[] = {
    }
 };
 
+static struct mcp251x_platform_data mcp251x_info = {
+        .oscillator_frequency = 12E6,
+        .board_specific_setup = NULL,
+        .power_enable         = NULL,
+        .transceiver_enable   = NULL,
+};
+
+#define MCP251X_CAN_INT_GPIO_PIN 25
+
 static struct platform_device bcm2708_spi_device = {
    .name = "bcm2708_spi",
    .id = 0,
@@ -502,9 +515,12 @@ static struct platform_device bcm2708_spi_device = {
 
 static struct spi_board_info bcm2708_spi_devices[] = {
    {
-      .modalias = "spidev",
-      .max_speed_hz = 500000,
+      .modalias = "mcp2515",
+      .max_speed_hz = 10000000,
       .bus_num = 0,
+      .platform_data = &mcp251x_info,
+      //.irq = gpio_to_irq(MCP251X_CAN_INT_GPIO_PIN), //Wird in bcm2708_mcp251x_init gesetzt, da hier nur Konstanten funktionieren und so die Funktion gpio_to_irq(MCP251X_CAN_INT_GPIO_PIN) nicht verwendet werden kann
+      //.controller_data = (void *) 21,
       .chip_select = 0,
       .mode = SPI_MODE_0,
    }, {
@@ -516,6 +532,21 @@ static struct spi_board_info bcm2708_spi_devices[] = {
    }
 };
 
+static void __init bcm2708_mcp251x_init(void)
+{
+   printk(KERN_DEBUG "bcm2708_mcp251x_init: Entry\n");
+   if ((gpio_request(MCP251X_CAN_INT_GPIO_PIN, "MCP251x CAN INT") == 0) &&
+       (gpio_direction_input(MCP251X_CAN_INT_GPIO_PIN) == 0)) {
+      //Export GPIO to User Space
+      gpio_export(MCP251X_CAN_INT_GPIO_PIN, 0);
+      irq_set_irq_type(gpio_to_irq(MCP251X_CAN_INT_GPIO_PIN), IRQ_TYPE_EDGE_FALLING);
+      bcm2708_spi_devices[0].irq = gpio_to_irq(MCP251X_CAN_INT_GPIO_PIN);
+   } else {
+      printk(KERN_ERR "could not obtain gpio for MCP251x CAN bus interrupt\n");
+      return;
+   }
+}
+
 static struct resource bcm2708_bsc0_resources[] = {
    {
       .start = BSC0_BASE,
@@ -625,6 +656,7 @@ void __init bcm2708_init(void)
    system_serial_low = serial;
 
 #ifdef CONFIG_SPI
+   bcm2708_mcp251x_init();
    spi_register_board_info(bcm2708_spi_devices,
          ARRAY_SIZE(bcm2708_spi_devices));
 #endif


Regards

Axel
Posts: 6
Joined: Fri Aug 10, 2012 12:23 pm
by AxelB » Fri Aug 10, 2012 1:31 pm
@Leszek:
I'm used to work with the CAN bus and protocols like CCP and UDS, but not using Linux. You wrote that you are able to communicate with an ECU using CCP and UDS on the BeagleBone. Is this also based on Linux and SocketCan? Did you implement the protocols on your own or are they somehow already available?

Regards

Axel
Posts: 6
Joined: Fri Aug 10, 2012 12:23 pm
by bertr2d2 » Fri Aug 10, 2012 2:48 pm
@AxelB,

do you have other CAN controller/tools to do a busload test ? Would be very interesting to see,
which load could be achieved without lost frames with the combination MCP2515 and RaspberryPi ...
Posts: 86
Joined: Wed Aug 08, 2012 10:12 pm
by AxelB » Sat Aug 11, 2012 9:15 am
@bertr2d2:
I have CANalyzer available, so I can do a test at different bus loads next week. I also want to try to connect a second MCP2515 in order to see, if communication on two CAN busses is possible...
Posts: 6
Joined: Fri Aug 10, 2012 12:23 pm