CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ex_can.c does not work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rafaluc2001



Joined: 20 Mar 2016
Posts: 10

View user's profile Send private message

ex_can.c does not work
PostPosted: Mon Mar 21, 2016 5:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 5:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 7:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 8:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 9:05 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 9:07 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 9:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 10:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 4:52 pm     Reply with quote

link to my schematic hardware.

https://www.dropbox.com/s/q47e25oyit4ne2l/Monitor%20CAN.bmp?dl=0
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 5:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 5:51 pm     Reply with quote

No, I'm not using MCLR.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 21, 2016 6:08 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group