View previous topic :: View next topic |
Author |
Message |
fernandokestering
Joined: 03 Sep 2018 Posts: 21
|
Return CAN |
Posted: Thu Sep 06, 2018 5:29 am |
|
|
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: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Sep 06, 2018 6:10 am |
|
|
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
|
|
Posted: Thu Sep 06, 2018 6:20 am |
|
|
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
|
|
Posted: Thu Sep 06, 2018 10:32 am |
|
|
The program gets stuck in a loop in the 1939ReceiveTask (); // J1939ReceiveTask (). Has anyone ever had this problem? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Sep 06, 2018 12:35 pm |
|
|
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
|
|
Posted: Thu Sep 06, 2018 1:55 pm |
|
|
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: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Sep 06, 2018 2:45 pm |
|
|
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
|
|
|
fernandokestering
Joined: 03 Sep 2018 Posts: 21
|
[solved] |
Posted: Fri Sep 07, 2018 4:15 am |
|
|
Hi newguy
Thanks!!!![/code] |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Sep 07, 2018 5:08 am |
|
|
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
|
|
Posted: Fri Sep 07, 2018 6:52 am |
|
|
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. |
|
|
|