Ethernet, USB & CAN - C coding - Page 1
Forum section: electronics / beginners

author: sidharth
author_rank: Newbie
timestamp: November 18, 2013, 06:00:17 am
content: Hello All,I mostly work with Microchip micros. I need to learn to add ethernet, USB & CAN to my projects.I have searched online & there's so much data about these protocols, it's overwhelming! There are also these ready made modules available that can be used that convert from RS232 to whatever... but I'm not satisfied with these. I want to be able to build my own hardware, write my own driver software in C.My questions are:1) Where & how do I START to learn about USB, ethernet & CAN so that I can write some useful code in C that actually works? I'm not too big on theory, I'm more of a hands-on, get your hands dirty kinda guy.2) Does it make sense to but some of these development kits?All guidance / suggestions would be much appreciated.Thanks,Sid

author: David_AVD
author_rank: Super Contributor
timestamp: November 18, 2013, 06:04:20 am
content: Writing things like that from scratch will be time consuming. Maybe start with one of the chip vendor's dev kits and their USB / Ethernet / CAN frameworks?

author: Stonent
author_rank: Super Contributor
timestamp: November 18, 2013, 06:08:27 am
content: If you don't fully want to reinvent the wheel you can go with some existing stuff:ELM327 (PIC18 based)http://elmelectronics.com/obdic.htmlSTN1110 (PIC24 Based)http://www.obdsol.com/stn1110/For the CAN interface there's the MCP2551 and MCP2515If you search ELM327 on ebay or AliExpress you'll see a lot of devices that use a PIC18 but a pirated copy of the old ELM327 software. Some are USB, some are Bluetooth.

author: lapm
author_rank: Frequent Contributor
timestamp: November 18, 2013, 07:37:15 am
content: I would definitely not recommend trying to do these from scratch. Ready made modules and software examples to them gets you started quickly. That way you don't loose interest on what you are trying to do and have known working example if you decide to dig in deeper later.

author: hans
author_rank: Super Contributor
timestamp: November 18, 2013, 09:43:20 am
content: Implementing USB or Ethernet stacks requires reading documents carefully, going through tons of driver code from demo's and others plus lots of "digital probing" (WireShark, other USB analyzer tools out there) to make it work.I think it is a good learning experience, but also quite a high learning curve.Nevertheless, if you want to do anything at all with these peripherals, you need hardware. You can bake your own, it's not that hard (USB: tons of PICS, Ethernet: ENC28J60 or PIC32 + MII ethernet Phy like KSZ8051MLL, CAN: PIC with CAN and MCP2551, or MCP2515+MCP2551). Otherwise, get an evaluation board from Olimex or the other quadruple million vendors out there.With any hardware in hands, I would search for demo applications so you can verify your hardware setup is working OK (SPI communication OK, crystal's OK, etc.).If you understand the example application, it's your decision: spenda lotof time to write your own stack or search for a decent open source one and actually implement your application.

author: matkar
author_rank: Regular Contributor
timestamp: November 18, 2013, 05:54:06 pm
content: I mostly work with Microchip PIC18F series of microcontrollers. I use CAN a lot. I have adopted Microchip's CAN library, corrected a few bugs, added some of my stuff and use it regularly in my projects. For the USB I have tried Microchip's CDC example years ago and I haven't found a problem there. Nowadays I mostly use FTDI products (serial and parallel interface) for USB connectivity. I have tried Microchip's TCPIP stack with ENC28J60 and MRF24WB0MA module as well and haven't found any problems there except for the flash consumption.None of the above is something you will be able to master without a sheer amount of studying the documentation. Using libraries will save you a lot of time but you still have to understand their internals, requirements and be able to configure them.

author: Stonent
author_rank: Super Contributor
timestamp: November 18, 2013, 09:17:52 pm
content: If you're just doing CAN without a vehicle application it might be feasible. But if you want to use it in a vehicle, you've got a lot of protocols to learn.

author: sidharth
author_rank: Newbie
timestamp: November 19, 2013, 04:23:38 am
content: The road ahead does not look particularly easy... if I write my own stack / drivers / libraries, but I will.To save time... I'll have to start with ready made libraries n stuff... for now!Thank you all for your suggestions. Much appreciated.