Hi all. I am contemplating a personal project involving CAN bus. Something that will listen to existing communication between modules on my car, grab a couple of pieces of pertinent data, and do something according to the values. However, aside from playing around with a cheap Bluetooth ELM327 clone dongle and Torque Pro on my phone to query OBD data, I haven't ever done much with CAN bus at a lower level. I have been doing some research, which is making my head spin, and I have some questions that I hope some of you can answer.
I gather there are two major components needed: a controller and a transceiver. There are some MCUs that feature an integrated controller. Is it better to go for one of those, or a separate controller? Also, are isolated transceivers only necessary when your device is not powered by a source common to the other devices on the bus?
I have most experience with AVR, so have been looking at the AT90CAN and ATmegaXXM1 range. I get the impression the former is quite an old design, but the latter has a bunch of stuff I don't need like a PSC, current source, DAC, etc. Am also considering the STM8A, as I have been meaning to get into STM8, but for some reason they only come in packages with a massive number of IOs that I won't need. There's also the STM32F042 that looks appealing (and cheap), but getting into Cortex M0 seems intimidatingly complex to me. For standalone controllers, it seems the MCP2515 is essentially the only game in town, which must be why everyone and their dog is using it. Is it better than integrated controllers from Atmel or ST? No such dearth of transceivers, though. The NXP TJA1057 looks good to me and is cheap, but again, for some reason everyone seems to use the MCP2551...
If I want only to silently tap into existing communications on the bus (I will never be transmitting any data), I gather I need to do so with a controller that supports 'listen-only' mode, right? I also see transceivers commonly feature a 'silent' mode where the transmitter is disabled; is this necessary too or just a fail-safe? On a related note, if I wanted to put my device into a standby/sleep mode (woken up only by user input, not bus activity), would it be a good idea to power-down the transceiver? Or do I need one that specifically has a 'sleep' mode?
What kind of clock source will I need for an MCU with integrated controller? They all say that an external crystal is recommended, but does this apply even if I'm only listening on the bus? Or, if I were to use an MCP2515, can one crystal run that and the MCU? That is, by hooking the crystal to the MCP2515, then take its CLKOUT and run the MCU off that? Or vice-versa?
Regarding the general procedure for receiving messages, it seems to me that a common overall principle shared by many controllers is thus:
1. Set some kind of filter or mask on the intended message ID in the controller - the controller will then only act on matching messages appearing on the bus.
2. A receive interrupt can be configured to occur whenever such a message is received, so that I may act upon it.
3. The controller will store such messages in a buffer, from where my code can retrieve the data.
What happens if you don't read the message data from the buffer before another is received? I guess it would just be overwritten? Or will it block new reception? Also, all the controllers I've looked at have a varying number of message buffers, but I'm not sure how they're used. Is it so you can have some kind of FIFO of received messages? Or so that you can receive and store messages with multiple widely different IDs at the same time?
Finally, my vehicle has the CAN bus self-terminated within the two modules at either end of the bus (the PCM and instrument cluster), so any potential device I add will effectively be in the middle of the bus. Is this what's called a 'stub' or 'spur'? I previously understood that such stub connections didn't need any kind of termination, but I saw reference in a datasheet of a transceiver (I forget which one) that some kilohms of termination may be required on stub nodes. I don't understand why that would be.
Sorry for the barrage of questions.
But I hope you all can throw some light on some of these matters for me.