CE034 - CAN Loopback
Transmitting the message and receiving it back in the Loopback mode
About this Code Example
If the Loopback mode is activated, the module will connect the internal transmit signal to the internal receive
signal at the module boundary. The transmit and receive pins revert to their port I/O function.
In this code example we have initialized the outdata registers with some values and then after initializing
the CAN module for the loop back mode we have transmitted the same data on the Tx Line , The same data is
received in the Rx line in the loopback mode and after receiving it in the Rx Buffer we compare it with the
values what we have transferred from the outdata register , If the values are same then we switch on the LED
on Port D which is there on the Development Board .
The same is done with CAN1 and CAN2
How to set up the board and view the working of the code
Place the dsPIC30F6014A PIM in the dsPICDEM 1.1GP Board and connect it to the ICD2 .After loading the code
in the device the running the device , all the four LED on the board should turn on .
You can also observe the working using the Debugger , See that when you place the breakpoint after the
receiving the data you will get the same data in the receive registers that you transmitted from the
outdata registers.These registers can be viewed in the watch window of MPLAB IDE.
How to Calculate the value to NTq ,BRP
FBAUD = 1 MBPS so we have to select value for FTq and N
BRP = (FCAN/(2*FTq))-1
FCAN = 30MHZ,Since BRP has to be a valid Integer for Maximum speed the value of FTq has to be 15MHz
so BRP becomes 0
Since the value of N can vary between 8-25 according to the CAN Protocol it will depend on the CAN
Speed on which you are operating the bus and your Processor Frequecny
So with 30MHz and 1Mbps you can have maximum value of N as 15 .
- Oct 7, 2011
Reloaded zip file.
- Jul 22, 2011
First upload to ECS