USB-CAN Bus

The purpose of this project is a simple and easy to use USB <> CAN bus interface. Heart of the circuit is an Atmel AVR ATmega162 microcontroller which controls the Communication between FTDI FT245BM USB to parallel converter and Philips SJA1000 Stand-alone CAN bus controller.
The SJA1000 is memory mapped into memory space of the AVR, which reduces data and address line handling and increases data transfer speed.
An FT245BM handles all USB communication and provides data transfer from and to PC application. An extra EEPROM can store the multi device template for the FT245BM.
A Philips PCA82C250/251 works as CAN controller interface.

Firmware is written in C, compatible to latest compiler version WinAVR.

The firmware is now compatible to run on a CANDIP module. The download include a pre-compiled firmware file to flash into a CANDIP module. Both pins for LED connection remaining the same.

See the CANDIP homepage for detail of the required hardware CANDIP/M162 .

Documentation and Source code

CAN-Control
CAN-Control
CAN-Control_v1.0b8.zip
Version: 1.08b
22.9 KB
9787 Downloads
Details
CAN-Control Source Code
CAN-Control Source Code
can_control.7z
5.2 MB
11433 Downloads
Details
CAN-USB Target files
CAN-USB Target files
CAN_BUS_Interface_v2_Target.zip
215.4 KB
6270 Downloads
Details
CANHacker
CANHacker
CANHackerV2.00.01.zip
Version: v2.00.01
1.8 MB
7475 Downloads
Details
EEPROM Template
EEPROM Template
Eeprom_Template.zip
550.0 B
4913 Downloads
Details
PCB in Gerber Format
PCB in Gerber Format
CAN_BUS_Interface_v2_Gerber.zip
262.4 KB
4908 Downloads
Details
Sourcecode
Sourcecode
Firmware_v1.09.zip
Version: 1.09
27.9 KB
6445 Downloads
Details
USB-CAN Bus Interface - Documentation
USB-CAN Bus Interface - Documentation
Documentation_Iss.F.pdf
Version: F
82.7 KB
15187 Downloads
Details
USB-CAN Bus Interface - Schematic & Board in Eagle
46.1 KB
9102 Downloads
Details
USB-CAN Bus Interface schematic
148.3 KB
19182 Downloads
Details
USB-CAN Bus PCB in PDF Format
223.7 KB
10000 Downloads
Details

CAN Hacker v2.00.01

Link

Homepage/Forum: www.canhack.net (German language only)

127 thoughts on “USB-CAN Bus

  1. hi,

    i have a question about yourCANBUS software.

    your CANBUS software support to DS401 CANopen protocol.

    thanks.

    • My Software doesn’t support any specific CAN protocol.
      It’s just a simple example to show and send CAN bus data, no further evaluation of these data is done.

    • Red LED means an error was detected.
      But there are various reason for errors. So may you read the ECR register to see what was the last error.

  2. I’m interested in building the adapter, but I don’t have much uC experience.

    If I build and flash successfully, will the adapter appear the same to the computer/CAN device(s) as a parallel-CAN adapter? I.e. can I use it as a drop-in replacement?

    • Dependent on the driver you will install, the adapter will appear either as VCP-Virtual Comm Port or as USB device where your software must support FTDI D2XX.

      In any case the adapter will use a Lawicel compatible protocol.

  3. Hi
    i would like to know how mutch CAN frames this design can handle

    Does it support DMA at 1MB/s
    Best Regards
    Jacob

    • If you use the FTDI D2XX driver to access the USB connection the device will definately handle 1MBit/s.

  4. Hi, do you sell the PCB somewhere?
    Maybe the plain predrilled PCB without electronics?

    Mark

    • I do not sell anything of my projects stuff.

      See the last link to the eBay shop on the page. They to sell hardware based on my circuit.

      I have no relation to this shop so keep in mind there will be no support regarding there products.

      Any PCB manufacturer can easily make PCBs out of the Gerber data I provided.

  5. Hi, thanks for your reply.
    Can you please upload the *.T3000 file of your CANUSB schematic?
    It would help me a lot.

    Thank you in advance.
    Mark

  6. Good day.

    I have a problem.
    There is a CAN BUS line with 500 Kb/s speed.
    CAN USB adapter uses FTD chip which emulates COM port.
    I feel that speed of COM port is less than 500kb even if port speed set greater than 500kb/s (Port settings). And I know what not all CAN messages are catched. (different results at the same input params).
    COM port slower than CAN BUS.
    Help please.

    • Assuming you talk about my CAN interface.
      The COM port settings doesn’t matter at all since we are talking over USB and even the uC talks to the USB chip in the interface by a parallel bus.

      But I agree with you, the VCP driver is somewhat slower than the D2XX driver which can be used to access the USB connection. If you want full speed you need to use D2XX.

  7. Thanks for answer, Michael.
    I hope that CanHacker v2 supports connection through D2XX driver.

  8. Goodday 🙂
    What is connection name in CANHACKER through D2XX driver? It`s called “USB Serial”?

    • As far as I know CANhacker don’t uses the D2XX driver but VCP.

      The name which will show up in CANhacker depends on what you have programmed in the device EEPROM. If nothing is programmed or an EEPROM is not used it might be that “USB Serial” will be shown. At least it makes sense 😉

  9. Hello,

    is it better to use D3 to power the Circuit or to use the external power via Can_VCC (7805) without D3?
    Can I use both power supplies simultaniously?

    Thank you in advance.

    Mark

    • You can use either power supply, even simultaniously. The device works at low power so no problem for the USB.
      D3 will block reverse feeding of the USB in case you power from extern.

  10. Hi,

    do you also have a T3001-File? T3000 can only be produced by PCB-Pool.
    The Eagle-File seems to be an old version without ground planes and rectangular vias.

    Mark

  11. Hi,

    sorry for spamming your website 🙂

    Just checked the Gerber-Files. They are also Rev. B only.
    Can you please update them to Rev. C?

    Thank you in advance.

    Mark

  12. Target files are up to date now, Gerber as well.
    Eagle files were just a conversion out of Target. I do not work with Eagle so no support on this.

    • What updated version, hardware or firmware?

      And may you can describe what kind of problems you have?

  13. Hi Michael

    Cannot open any of the files for USB CAN bus. Error
    message states”does not appear to be a valid archive”

    Regards
    Gennaro

  14. Hello Michael !
    I need your help.
    Following your example, I decided to create open-source CANbus sniffer, using the same communication protocol as well as in your project. Hardware implemented on the microcontroller LPC2129 and successfully working with the program CANHacker. I also write a program similar CANHacker, but it does not work. Data exchange between FTDI and the program on a PC is not working properly. I’ve been fighting with FTDI 2 months = (data flow from the FT232R is taken incorrectly. I used the library D2XX. Can you put the source code CANControl? Or give advice how to take data from the chip FTDI. Regards, Artem. Russia, Novosibirsk
    Regards, Artem. Russia, Novosibirsk

  15. Hello Artem,
    I am also creating CANbus Sniffer with LPC2129 and I will appreciate your help. Can you send me your code?

    Best regards,
    Marko
    Serbia

  16. Hello Michael
    Problem with running CAN-Control software on one computer.Error message is “application failed to start
    due to incorrect configuration”. I have reinstalled software but problem exsists.Computer sees the USB CAN
    adaptor. The same setup works OK on other computers.
    I run Windows XP on all computers.
    Regards
    Gennaro

  17. The souce code for CAN-Control is available for download now.

    @Alexey
    Not sure what compatibility is required for LabView. As long as you can open the USB port in VCP mode you can access the interface like a serial COM port.
    Implementing the Lawicel protocol shouldn’t be that hard.

    @Gennaro Arena
    Never got such error. Possibly an MFC redistribution package is missing. You need one for Visual Studio 5 C++.

  18. I have put together your design. I can use CAN COntrol to interrogate version ok, but says “failed to send message” if I try sending a message.

    Also, any register I read contains its own address, ie 0x01 = 0x01, 0x02 = 0x02 …

    LEDs don’t blink, and bus is idle when measured by scope

    What am I doing wrong?

    • If you can read the version then communication between the AVR and Pc via USB is fine. If sending of messages fails the AVR reports an error back. So I would guess there is a problem either in communication beween AVR and SJA1000, or SJA1000 and CAN bus. You may check your circuit for bad soldering, shorts and so on.

  19. Michael, i use a com port in LabView programm. Thanks.

    Have you a command description for USB-CAN Adapter to send via com port/terminal? (like as initialize, open session? close session…)

  20. Hi Michael,

    I added a 1k0 resistor between SJA1000 Chip Select and Ground. This fixed the Send and register problem.

    I found CAN_CS defined in the firmware, but I can’t find under what condition it asserts (active low) the CAN_CS line. I will try to change the firmware so I don’t need to modify the board permanently. Is this a software bug, or do I have something wrong in the hardware? I think it must be hardware because no-one else has the problem, but not sure.

    Thanks

    Edward

    • The chip select is active low. The internal pull-up’s from the AVR will pull high when not used, a low level will be forced by the port while accessing the SJA1000.

  21. Is it possible to have user documentation for the
    CAN Control software ? Something simple please

    Kind regards
    Gennaro

  22. I found error in the firmware ver 1.0.7. Baudrate values are have wrong values. If you see file sja1000.h you can find something wrong.
    Please check lines 92-100 from sja1000.h file
    #define BTR0_125k 0x03
    #define BTR1_125k 0x1C

    #define BTR0_250k 0x03
    #define BTR1_250k 0x1C

    #define BTR0_500k 0x01
    #define BTR1_500k 0x1C

    BTR0 and BTR1 can not have same value for different bitrates. And BTR0_500k have value for 250k in really.
    I have bitrates calculator from ZlgCAN2004 SJA1000_Btr01.exe. It possibles calculate BTR0 and BTR1 very easy. If you want, I can share this file.

    Below my suggestion
    #define BTR0_250k 0x01 //0x03 ??? ???????????
    #define BTR1_250k 0x1C //0x1C

    #define BTR0_500k 0x00 //0x01
    #define BTR1_500k 0x1C //0x1C
    It work very well.
    But it not ideal values. There are many variants…

      • Hello! Please can you have a firmware update with Sukhovey Aleksey suggested values?
        “Below my suggestion
        #define BTR0_250k 0x01 //0x03 ??? ???????????
        #define BTR1_250k 0x1C //0x1C

        #define BTR0_500k 0x00 //0x01
        #define BTR1_500k 0x1C //0x1C”

        Thank you and GOOD JOB!

    • Sukhovey Aleksey can you share or send SJA1000_Btr01.exe. dorcky at gmail dot com. Thank You!

  23. Hello,
    can you upload the Target-File with *.T3001 Format. I can’t open your file.
    Thank You

    • The Taget files is already available for download, see CAN_BUS_Interface_v2_Target.zip.

      Use 7zip to open the files.

  24. Hello Michael,
    Is CAN-Adapter interchangeable with PEAK PCAN USB o LAWICEL ?
    Is compatible with FLASH MAGIC to downloadd via CAN BUS flash programming MCU Cortex m0 m3? (NXP Seminconductors Lpc11xx…Lpc17xx..)
    Thank You

  25. Hi Michael,
    (another question)..
    module CANDIP/M162 mounts an FT245BM ?
    Is fully compatible with firmware/HW MITRONICS ?
    Thank You

    • Do use CANDIP hardware you need to download the dedicated firmware I made. CANDIP uses different pins on the uC.

    • Hardware might be compatible but the protocol between interface and PC is not. As far as I know Peak uses a proprietary communication protocol.

  26. Hi Michael,

    I’m not found mega162 in my country,Can i use alternative mico in this project?

    Thanks for youe attention
    Best Regards ,
    Payam

    • As far as I know there is no drop in replacement for the ATmega162. You may contact Atmel.

  27. Hi Michael,

    I have made it work!

    The problem was I had the JTAG fuse set, which conflicts with the CS pin to the SJA1000.

    Writing this command fixed it:
    avrdude.exe -p m162 -c stk200 -C “ATmega162.conf” -P lpt1 -U hfuse:w:0xD9:m -F

  28. Hi, Michael,

    If I put a USB hub between an ARM9 usb host port and your target board, will it still work? FTDI has WinCE/Linux drivers for FT245. Without the hub, it should work. But i am not sure whether it will also work for a hub. Any comments?

    best regards
    Wanchope

    • Hmm never tried with a hub. But see now reason why it shouldn’t work.

      Give it a try and let me know 😉

  29. Hi Michael . In your Firmware 1.07
    problem with speed 500kbs . It works
    250kbs.In firmware 1.06 its all ok.

    • That’s a problem with baud rate values. Some work for your application others don’t. I succest to use customized baud rate values over fixed. This way you can use an online calculator to find the best values for your application.

  30. It is possible to make this interface on Atmega162-16PU (DIP 40)? It is possible to use firmware_v1.07.zip with Atmega162-16PU (DIP 40)?

    • Yes it is, but the DIP has a different pinning then the TQFP so schematic will not fit for the DIP. Firmware will work with both types, that’s only a hardware issue.

  31. What version of winAVR are you used?
    I want to compile project with right speed settings (250kbit/s) and Sergey’s remark.
    I re-compile with winavr 20100110. And it works with some problems. (size of HEX-file is NOT the same as firmware_1.07.hex)

    • I use the same WinAVR version.
      You are fine as long as the code compiles without errors.

      What are your problems?

      • Try to discribe (sorry for my English)
        I use CAN Hacker v2.00.01.
        CAN speed – 250 kbits (bus load – ~16 messages in 1second)
        CANHacker scan exchenge data and try to send 1 messsage with period (100…1000) ms

        With your HEX-file (firmware_1.07.hex) recive and transmit work well (I am embarrassed only in speed selection – select 500 instead of 250)
        With my hex (with changed BTR0_250k 0×01 and BTR1_250k 0x1C) CANHacker in “list” can-bus normal, but when I try send 1 message periodically – CANHacker stop send any data in Recive-table. Sending data – don’t work as wall. After reConnect – “listening” again work normal.

          • So I assume v1.07 doesn’t work too?

            My problem is I sold all CAN stuff and just have a single interface left. So I can’t perform any bench tests. However I have a car with CAN bus but never tried the interface. May I will give it a try.

  32. I can not get a response from the control module after sending data. (try from canhack and cancontrol)
    Although listening to see the packets sent and received by the module with diagnostic interface.
    What else is strange, I see that packets are transmitted on the bus and I can respond to requests for diagnostic interface, but directly with a control module for some reason does not work.

  33. Hello Michael,

    We have made up a few of the USBCAN interfaces, would you like us to send you one so you have two for testing?

    Cheers,

    Edward

  34. When I send CAN message the error message “FAILED TO SEND MESSAGE” comes
    up. The CAN CONTROL windows freezes the PC but the CAN USB is still sending the
    CAN message as it is running in the background. Cannot exit the software. PC does
    not respond to any instructions.

    • The freeze shouldn’t happen since the error will generated only when you hit the SEND button and there was a failure. Even when the interface will not respond a timeout will trigger.

      Do you have the “Cyclic” option activated, that would be an explanation for your problem.

      • The test I perform needs CAN IDs sent in Cyclic mode every 100ms. On both my CAN USB interfaces the problem is the same. The ECR read out
        is. TX Error; Type:Other;Segment:Acknowledge slot. The SJA 1000 datasheet explanation of this error makes no sense to me.

        • The error description indicates a missing acknowledge from at least one CAN node on the bus.
          In other words one node sends the a frame but no other node confirms reception. So you may check your wiring, correct baud rate setup of all nodes etc.

  35. Hi
    i tryed to compile with WinAVR-20100110 (and the makefile given )the same code just for test and it not wok
    can someone help

  36. i have 2 boards connected each other and using canhacker twice i am sending from 1st canhacker and receive from the 2ed canhacker , when i send i get bus error from just 1 board and nothing received
    i can send you the hex file i got

    • Did you change something in code?

      I also told you in a earlier Email that you should use a terminal program for testing and read the error register when the red LED is on. Compare the error register content with the SJA1000 datasheet. This will tell you in detail what the reason for error.

  37. Hi Michael,

    Can it be that the Eagle v2 file is missing the schematic? There’s only a component library and the board inside the .zip. I have an excess stock of FT245R and thought I could put them to some use.

    Regards,
    Christian

    • Yes that’s possible. The Eagle board is the result of a conversion from Target3001, the native format. Don’t remember if there was a Eagle schematic or not, at least I don’t have one.

    • CAN_INT is a signal from SJA1000 to ATmega162. That’s an interrupt to tell the ATmega that some events occurred and need to be handled.

  38. This project may be of interest to users here. It could easily be adapted to be compatible with
    this hardware. This only applied to those using C# / VB. At the minimum it will need to add the USB PID/VID to the accepted list.
    Many CAN USB adaptors come with nasty DLLS that you need to ‘PInvoke’ (like peek/poke). They were not designed for modern languages that use managed code. You have to write/use a ‘C# wrapper’ to access the DLL. You can NOT add them to your VS2010 and start using them.
    When you distribute your application – the user has to install USB hardware drivers, then install DLLs (which fills the windows system directory with all kinds of rubbish), then your application. The application talks to the DLL which talks to the USB driver which talks to the hardware. Yuck.

    So.. If you want a solution that uses a very simple USB hardware device driver (from FTDI) and a c# library (instead of the dreaded DLL) that is actually referenced (or linked?) as managed code in your project.. AND is provided in source code form.. And is open source.. And can be compiled as 64bit code.. Then this is the solution you should be looking at
    http://sourceforge.net/projects/canusb/
    (Note: You will need to take the project from SVN/CVS as the zip file may be old..)
    It also happens to be one of the cheapest CAN hardware devices out there..
    The library can also be compiled with Mono instead of VS2010
    Some keywords:
    CAN USB adaptor C# library 64bit CANUSB Managed code .NET library with no DLL nonsense!

    I hated working with DLLs.. callbacks from an unmanaged code that bloats the system directory.. that needs permissions to install.. can’t be recompiled and so on..
    If you are working with C#, then it’s the right way to do it..

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments will be moderated! Spam deleted immediately!
Before you submit form:
Human test by Not Captcha