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

Return CAN

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



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

Return CAN
PostPosted: Thu Sep 06, 2018 5:29 am     Reply with quote

I was able to make the CAN network return something, it follows:
CAN_GETD (): BUFF = 1 ID = 0CFE6CEE LEN = 8 OVF = 1 FILT = 2 RTR = 0 EXT = 1 INV = 0
DATA = 00 3F FF C0 00 00 00 00

However, it is not yet valid data to be recognized by the J1939 library provided by CCS.
The bus speed is 250kbps.
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Sep 06, 2018 6:10 am     Reply with quote

quick comment

While I don't use CAN, first place to look is PIC clock speed. You'll need to use a real xtal/2caps configuration, then check actual clock frequency as well as CAN clock speed. Both of these must be confirmed as if either is 'off' just a tad... the CAN data could be slewed or corrupted.
Others, who use the CCS CAN driver can help with the setup/configuration, though you'll have to provide them more details.

Jay
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 06, 2018 6:20 am     Reply with quote

I am using the PIC18f4520 with a frequency of 20Mhz and the MCP2515 also with a frequency of 20Mhz.
Configuration of the MCP2515:

J1939_BAUD_RATE == 250000


#define CAN_BRG_PRESCALAR 3
#define CAN_BRG_PHASE_SEGMENT_1 3
#define CAN_BRG_PHASE_SEGMENT_2 3
#define CAN_BRG_PROPAGATION_TIME 0
#define CAN_BRG_SYNCH_JUMP_WIDTH 0
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 06, 2018 10:32 am     Reply with quote

The program gets stuck in a loop in the 1939ReceiveTask (); // J1939ReceiveTask (). Has anyone ever had this problem?
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Sep 06, 2018 12:35 pm     Reply with quote

Does your CAN I/F have the proper pullups/terminators ?
IS the PIC SW configured for the other CAN device (same speed, etc )?
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 06, 2018 1:55 pm     Reply with quote

I am receiving this information from the CAN network, PGN 65217 (total distance)
18FEC1EE
DATA = C2 45 73 00 3E 3D 73 00
How do I convert to KM?
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Sep 06, 2018 2:45 pm     Reply with quote

I'd say read the manual or datasheet for the device transmitting that data to the PIC. It HAS to be documented.
I could 'guess' and say each byte is one digit of the odometer reading in some weird, abstract encoding though I'd use PBCD.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Thu Sep 06, 2018 5:47 pm     Reply with quote

Did you try googling "pgn 65217"?

http://www.copperhilltechnologies.com/electronic-logging-devices-eld-sae-j1939-and-sae-j1708j1587-parameters/

0x7345c2 = 7554498. The units are "5m / count", so multiply by 5 to get 37,772,490. Convert to km by dividing by 1000: 37,772.490 km.
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

[solved]
PostPosted: Fri Sep 07, 2018 4:15 am     Reply with quote

Hi newguy
Thanks!!!![/code]
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Sep 07, 2018 5:08 am     Reply with quote

The reference newguy posted doesn't say the data elements are reversed..hmmm
DATA = C2 45 73 00 3E 3D 73 00

while the data is split, 4 bytes = total distance, 4 bytes are 'trip' distance

'somewhere' newguy saw that
C2 45 73 00 has to be reversed into 00 73 45 C2
something I would not have known to do.
It also requires more code to complete the task.

It does point out that you NEED to find original documentation about ! In this case , locate the SAE J1939 papers.

Jay
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Fri Sep 07, 2018 6:52 am     Reply with quote

temtronic wrote:
The reference newguy posted doesn't say the data elements are reversed..hmmm
DATA = C2 45 73 00 3E 3D 73 00

while the data is split, 4 bytes = total distance, 4 bytes are 'trip' distance

'somewhere' newguy saw that
C2 45 73 00 has to be reversed into 00 73 45 C2
something I would not have known to do.
It also requires more code to complete the task.

It does point out that you NEED to find original documentation about ! In this case , locate the SAE J1939 papers.

Jay


No it's just a big endian/little endian thing. Been playing with J1939 or J1939-like protocols enough to recognize that the LSB corresponds with the low byte (byte[0]) in the data packet, or big endian. The NMEA 2000 protocol is a superset of J1939 with variable number of packets in which the data can be packed in any order. The only "constant" is that data is always packed big endian.
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