View previous topic :: View next topic |
Author |
Message |
rafaluc2001
Joined: 20 Mar 2016 Posts: 10
|
ex_can.c does not work |
Posted: Mon Mar 21, 2016 5:18 am |
|
|
Could someone please show what is missing to make the example ex_can.c work? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Mar 21, 2016 5:26 am |
|
|
Nothing... provided you use real hardware,correct PIC,etc. ALL of the CCS examples should work fine. At least the ones I've tried since PCM v2.543.
Jay |
|
|
rafaluc2001
Joined: 20 Mar 2016 Posts: 10
|
|
Posted: Mon Mar 21, 2016 7:57 am |
|
|
So how do to set the speed and the ID you need or how it could do a test only with a 18F2580 and MCP2551 to see examples working? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Mar 21, 2016 8:25 am |
|
|
These are set by the defines:
Code: |
#define CAN_BRG_PRESCALAR 4 //Set CAN Baud Rate to 125K
#define CAN_BRG_PHASE_SEGMENT_1 1 //Tq = (2*(1+PRESCALAR))/(Fosc/2)
#define CAN_BRG_PHASE_SEGMENT_2 1 //Tq = (2*(1+4)/(20000000/2) = 0.000001
#define CAN_BRG_PROPAGATION_TIME 2 //Baud Rate = 1/(((PHASE_SEGMENT_1+1)+(PHASE_SEGMENT_2+1)+(PROPAGATION_TIME+1)+1)*Tq)
#define CAN_BRG_SYNCH_JUMP_WIDTH 0 //Baud Rate = 1/(((1+1)+(1+1)+(2+1)+1)*0.000001) = 125000
|
and the 'RESPOND_TO_ID' defines. |
|
|
rafaluc2001
Joined: 20 Mar 2016 Posts: 10
|
|
Posted: Mon Mar 21, 2016 9:05 am |
|
|
It did not work yet!
Is it possible you have something working for me to learn?
If possible of course! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2016 9:07 am |
|
|
Ex_can.c is very dependent upon having the correct hardware.
Post a schematic of your hardware. Please don't be using a simulator
such as Proteus. Use real hardware.
Post a link to a photo of your hardware. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Mar 21, 2016 9:15 am |
|
|
and getting the timing values right is critical. Use the online calculator program, but be very careful to specify your chip's clock rate right. Some want Fosc, and some (most) want Fcy (Fosc/4 for a PIC18, but Fosc/2 for the DsPIC family). |
|
|
rafaluc2001
Joined: 20 Mar 2016 Posts: 10
|
|
Posted: Mon Mar 21, 2016 10:27 am |
|
|
I use Pic18f2580 with MCP2551.
#use delay (clock = 20000000)
#use RS232 (baud = 9600, xmit = PIN C6, C7 VN = PIN)
#include "can-18xxx8.c"
set_tris_b ((* & 0xF93 0xFB) | 0x08); // B3 is out, b2 is in |
|
|
rafaluc2001
Joined: 20 Mar 2016 Posts: 10
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2016 5:43 pm |
|
|
You have the MCLR resistor on the wrong pin. You have it on the RA0 pin.
It should be on MCLR. (Assuming that you're not using the NOMCLR fuse). |
|
|
rafaluc2001
Joined: 20 Mar 2016 Posts: 10
|
|
Posted: Mon Mar 21, 2016 5:51 pm |
|
|
No, I'm not using MCLR. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2016 6:08 pm |
|
|
OK, do a loopback test. In this thread, I describe how to do this:
http://www.ccsinfo.com/forum/viewtopic.php?t=48915
This loopback test does not include the MCP2551, but at least it will prove
that your PIC and the CAN bus program and your test setup are working OK. |
|
|
|