Benefits that CAN bus brings in comparison to other serial protocols are already explained at first CAN bus article. Most of that benefits alongside with simplicity of the MCU's UART module can be found on MCP2542 click board. This click board can be observed like hybrid of CAN and UART which brings all the best from both.
MCP2542 Click Board
MCP2542 device serve as the interface between a CAN protocol controller and the physical bus. The devices provide differential transmit and receive capability for the CAN protocol controller. Designed for high-speed CAN FD applications up to 8 Mbps communication speed. The maximum propagation delay was improved to support longer bus length. The device meets the automotive requirements for CAN FD bit rates exceeding 2 Mbps, low quiescent current, electromagnetic compatibility ( EMC ) and electrostatic discharge ( ESD ).
Typically, each node in a CAN system must have a device to convert the digital signals generated by a CAN controller to signals suitable for transmission over the bus cabling (differential output). It also provides a buffer between the CAN controller and the high-voltage spikes that can be generated on the CAN bus by outside sources.
MCP2542 wakes up on CAN activity ( basic wake-up ). The CAN activity filter time is 3.6 μs maximum. It also wakes up after receiving two consecutive dominant states separated by a recessive state: WUP.
CANH and CANL are protected against battery short circuits and electrical transients that can occur on the CAN bus. This feature prevents destruction of the transmitter output stage during such a fault condition. The device is further protected from excessive current loading by thermal shutdown circuitry that disables the output drivers when the junction temperature exceeds a nominal limit of +175°C. All other parts of the chip remain operational, and the chip temperature is lowered due to the decreased power dissipation in the transmitter outputs. This protection is essential to protect against bus line short-circuit-induced damage. Thermal protection is only active during Normal mode.
Click board uses only 3 pin for communication with host MCU ( STB pin and UART lines ). There is RS232 connector as a standard port for CAN bus, and also additional through-holes which allows you to implement connection independent from MikroBUS standard.
Example
Click board is very simple for use. Everything sent from MCU's UART will be forwarded to the CAN bus and vice versa. Therefore functionality is simple our library is doing nothing more than storing received data to the buffer until previously defined characters arrives. Due to CAN bus characteristic that transmit node in same time can observe and read the state of the bus every module that transmits the message through the bus in same time receives it own message. Because of that it is implemented that UART reception is disabled while device transmitting the data.
#include "mcp2542.h" #include "resources.h" /* MODULE PINS ******************************************************************************/ sbit MCP2542_STB at LATA0_bit; sbit LCD_RS at LATB4_bit; sbit LCD_EN at LATB5_bit; sbit LCD_D4 at LATB0_bit; sbit LCD_D5 at LATB1_bit; sbit LCD_D6 at LATB2_bit; sbit LCD_D7 at LATB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; sbit LCD_BCK at LATG3_bit; sbit LCD_BCK_Direction at TRISG3_bit; /* VARS ******************************************************************************/ char read_buffer[ BFR_SIZE ] = { 0 }; char write_buffer[ BFR_SIZE ] = "MikroElektronika"; /* PROTOTYPES ******************************************************************************/ void system_init( void ); void display_init( void ); /* FUNCTIONS ******************************************************************************/ void system_init() { TRISA0_bit = 0; TRISE0_bit = 1; Delay_ms( 200 ); UART1_Init( 57600 ); Delay_ms( 200 ); } void display_init() { Lcd_Init(); Lcd_Cmd( _LCD_CLEAR ); Lcd_Cmd( _LCD_CURSOR_OFF ); Lcd_Out( 1, 4, "MCP2542" ); Lcd_Out( 2, 1, "Initialization" ); Delay_ms( 2000 ); Lcd_Cmd( _LCD_CLEAR ); } /* MAIN ******************************************************************************/ void main() { system_init(); display_init(); mcp2542_init(); while( 1 ) { if( Button( &PORTE, 0, 100, 1 ) ) { mcp2542_send( write_buffer ); Lcd_Cmd( _LCD_CLEAR ); Lcd_Out( 1, 7, "SENT" ); Delay_ms( 2000 ); Lcd_Cmd( _LCD_CLEAR ); } if( mcp2542_rdy() ) { mcp2542_read( read_buffer ); Lcd_Cmd( _LCD_CLEAR ); Lcd_Out( 1, 5, "RECEIVED" ); Lcd_Out( 2, 1, "MikroElektonika" ); } } }
This is simple example of transceiver node. Delimiter is "rn" and it actually represents the characters that must be sent at the end of each message. Without delimiter mcp2542_rdy() will never return that new message have arrived.
For more information you can download the package form Libstock or check the source code on our repository.
Summary
This was the device that extends your UART above it limits. It is excellent for situations when you need to extend your bus but keep the high speed or make it more resistance to noise and in same time to keep the simplicity of the UART.