Background
I'm developing a project which will require the modest microcontroller specs of:
- 8 12-bit, 10kHz ADCs
- 1kB of RAM
- 48-QFN or smaller footprint
- 20kbps daisy-chainable noise-resistant and error-correcting communication protocol
Signal processing requirements are fairly low, and most can be exported to the master processor in the system. The first three specs are easy to meet, and can be done for less than $2 in quantity. However, communication will be happening in a very electrically noisy environment, so noise-vulnerable networks like LIN and I2C are out. An additional argument against LIN is that I'd like to run the whole thing at 5V or 3.3V, and LIN transceivers require 12V, and so would require an extra regulator or wire per sensor board. I initially chose CAN for this task. However, CAN controllers add considerable cost, and I'm curious if this can be done in software.
CAN Physical Layer
The CAN specification defines the Data Link and Physical layers of the OSI network reference model. Many inexpensive 8-pin ICs, such as the NXP TJA1040/50, Maxim MAX3058/59, Microchip MCP2551, and TI SN65HVD1050 exist to implement the physical layer. Implementing the physical layer with D/A converters or op-amps would be difficult, if not impossible, so these ICs are well worth the $1 or so that they cost.
CAN Data Link/Protocol Layer
For the Data Link layer, some microcontrollers add CAN protocol modules onto the basic UART, I2C, and SPI communications layers. However, these are significantly more expensive than the basic chips.
Investigation of cost of CAN protocol modules
To substantiate this claim, here are a few popular micros in CAN and non-CAN versions, from the :
- ATmega16 - ATMEGA16M1 (with CAN): $3.87, ATMEGA168A (no CAN): $3.23
- dsPIC - DSPIC33FJ64MC802 (with CAN): $6.14, DSPIC33FJ64GP202 (no CAN): $5.48
- PIC18 - PIC18F2480 (with CAN): $6.80, PIC18F24J10 (no CAN): $2.10
- Cortex-M3 - STM32F103C4T6A (with CAN): $6.50, STM32F100C4T6B (no CAN): $2.73
To be fair, I only compared microcontrollers with equivalent memory sizes, however, many of the non-CAN versions are available with smaller memory sizes for less. External CAN controllers, like the Microchip MCP2515, are almost $2, so it's obviously more cost-effective to have the CAN integrated into the microcontroller if you have the option.
Interestingly, the ATmega part is by far the cheapest CAN-equipped part in Digikey's inventory.
Function of CAN protocol layer
The CAN module found in the dsPIC microcontrollers does the following:
The CAN bus module consists of a protocol engine and message buffering/control. The CAN protocol engine handles all functions for receiving and transmitting messages on the CAN bus. Messages are transmitted by first loading the appropriate data registers. Status and errors can be checked by reading the appropriate registers. Any message detected on the CAN bus is checked for errors and then matched against filters to see if it should be received and stored in one of the receive registers.
This seems fairly doable in software.
The Question
Can a software protocol layer be used implement the CAN specification with only an inexpensive UART-equipped microcontroller and a CAN transceiver? If so, do any open-source implementations exist?
Alternatively, can CAN transceivers be used with UARTs to implement a custom protocol? I'm OK with a single-master topology; I understand that arbitration can be hard to get right in a custom protocol.