Flowcode and Internal CAN
Posted: Thu May 13, 2010 9:32 am
CAN stands for Controller Area Network and is a popular bus which is heavily used in today’s automotive environment for communicating between microcontroller nodes where each node is responsible for completing or monitoring a specific task. CAN bus is also suitable for applications other than just automotive due to its low cost, message-based protocol, high immunity to noise and maximum transmission distance between nodes.
Some of the newer PICmicro and AVR microcontrollers have been fitted with internal CAN modules, which allow for the device to connect up to the bus using minimal external circuitry. The advantages of using the internal modules over using an external CAN chip are that there is less circuit complexity and cost due to the reduced parts count, plus faster transmissions due to direct register read/write access.
A full manual detailing our CAN solution and Flowcode’s CAN component can be found here:
http://www.matrixmultimedia.com/lc_adva ... .php#EB744
There is also a good help file available for use with the Flowcode component by selecting the component in Flowcode and then clicking the help button on the sidebar.
The internal CAN functionality is loaded into Flowcode based on which target family you are using.
PICmicro
For PICmicro devices with internal CAN you can modify the CAN component by updating the C code and the OCX files that drive the operation of the CAN component. These files can be found in the “Flowcode V4/Components” directory. Once you have done this the properties, hardware macros will all work seamlessly with the internal CAN registers. A clock speed of 20MHz is recommended for the default baud settings but if you require an alternative clock speed then you simply have to use the calculator included in the component properties to work out a feasible baud rate.
Here are some examples of working baud rates at different crystal speeds.
125KHz @ 8MHz – BRGCON1=0x3 BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 16MHz – BRGCON1=0x7 BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 24MHz – BRGCON1=0xB BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 40MHz – BRGCON1=0xF BRGCON2=0xD1 BRGCON3=0x03
250KHz @ 8MHz – BRGCON1=0x1 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 16MHz – BRGCON1=0x3 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 24MHz – BRGCON1=0x5 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 40MHz – BRGCON1=0x7 BRGCON2=0xD1 BRGCON3=0x03
Supported PICmicro devices with internal CAN functionality include: 18F2480, 18F2580, 18F2585, 18F2680, 18F2682, 18F2685, 18F4480, 18F4580, 18F4585, 18F4680, 18F4682 and 18F4685.
AVR
For AVR devices with internal CAN you again must modify the component by replacing the C code that drives the component. With the AVR devices the internal CAN organisation is not the same as the standard Microchip external CAN chip so the properties of the CAN component do not match. This means that any settings from the Flowcode CAN component properties will be lost so therefore the functionality needs to be brought out into your Flowcode program. If you are relying on these properties in an existing program then you will have to edit your program or use the existing method of using the Microchip external CAN driver. Alternatively you can use one of the PIC devices mentioned above.
The AVR internal CAN driver only supports a bus speed of 125KHz and only supports the following crystal frequencies: 4MHz, 6MHz, 8MHz, 12MHz, 16MHz, 18MHz and 20MHz. Any other clock speed setting in the project options window will result in a compilation error without manually editing the C code behind the CAN component.
Supported Atmel AVR devices with internal CAN functionality include: AT90CAN32, AT90CAN64 and AT90CAN128.
Please note that the modification for the internal CAN module of AVR devices is provided as-is and we can offer very limited support for it at the present time.
CAN Driver Chip
The CAN bus operates using a differential signal to allow for the high noise immunity. The I/O pins of the microcontroller cannot directly produce a differential signal so an external driver chips is still required for the CAN to work correctly. This is however much less then the cost of the external CAN controller chip.
Here is a basic circuit to allow you to use the internal CAN with an external CAN driver chip to produce a fully operational system.
Some of the newer PICmicro and AVR microcontrollers have been fitted with internal CAN modules, which allow for the device to connect up to the bus using minimal external circuitry. The advantages of using the internal modules over using an external CAN chip are that there is less circuit complexity and cost due to the reduced parts count, plus faster transmissions due to direct register read/write access.
A full manual detailing our CAN solution and Flowcode’s CAN component can be found here:
http://www.matrixmultimedia.com/lc_adva ... .php#EB744
There is also a good help file available for use with the Flowcode component by selecting the component in Flowcode and then clicking the help button on the sidebar.
The internal CAN functionality is loaded into Flowcode based on which target family you are using.
PICmicro
For PICmicro devices with internal CAN you can modify the CAN component by updating the C code and the OCX files that drive the operation of the CAN component. These files can be found in the “Flowcode V4/Components” directory. Once you have done this the properties, hardware macros will all work seamlessly with the internal CAN registers. A clock speed of 20MHz is recommended for the default baud settings but if you require an alternative clock speed then you simply have to use the calculator included in the component properties to work out a feasible baud rate.
Here are some examples of working baud rates at different crystal speeds.
125KHz @ 8MHz – BRGCON1=0x3 BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 16MHz – BRGCON1=0x7 BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 24MHz – BRGCON1=0xB BRGCON2=0xC9 BRGCON3=0x02
125KHz @ 40MHz – BRGCON1=0xF BRGCON2=0xD1 BRGCON3=0x03
250KHz @ 8MHz – BRGCON1=0x1 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 16MHz – BRGCON1=0x3 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 24MHz – BRGCON1=0x5 BRGCON2=0xC9 BRGCON3=0x02
250KHz @ 40MHz – BRGCON1=0x7 BRGCON2=0xD1 BRGCON3=0x03
Supported PICmicro devices with internal CAN functionality include: 18F2480, 18F2580, 18F2585, 18F2680, 18F2682, 18F2685, 18F4480, 18F4580, 18F4585, 18F4680, 18F4682 and 18F4685.
AVR
For AVR devices with internal CAN you again must modify the component by replacing the C code that drives the component. With the AVR devices the internal CAN organisation is not the same as the standard Microchip external CAN chip so the properties of the CAN component do not match. This means that any settings from the Flowcode CAN component properties will be lost so therefore the functionality needs to be brought out into your Flowcode program. If you are relying on these properties in an existing program then you will have to edit your program or use the existing method of using the Microchip external CAN driver. Alternatively you can use one of the PIC devices mentioned above.
The AVR internal CAN driver only supports a bus speed of 125KHz and only supports the following crystal frequencies: 4MHz, 6MHz, 8MHz, 12MHz, 16MHz, 18MHz and 20MHz. Any other clock speed setting in the project options window will result in a compilation error without manually editing the C code behind the CAN component.
Supported Atmel AVR devices with internal CAN functionality include: AT90CAN32, AT90CAN64 and AT90CAN128.
Please note that the modification for the internal CAN module of AVR devices is provided as-is and we can offer very limited support for it at the present time.
CAN Driver Chip
The CAN bus operates using a differential signal to allow for the high noise immunity. The I/O pins of the microcontroller cannot directly produce a differential signal so an external driver chips is still required for the CAN to work correctly. This is however much less then the cost of the external CAN controller chip.
Here is a basic circuit to allow you to use the internal CAN with an external CAN driver chip to produce a fully operational system.