View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 28, 2012 5:02 pm |
|
|
I made Loopback mode work with a 18F46K80 with compiler vs. 4.120
in hardware (It also works with vs. 4.135). The 18F46K80 is in the same
family as your PIC so it should work for you too. I'm using a 20 MHz
crystal. Here's what I had to do:
1. Make a project for Ex_CAN.c
2. Change the top lines so they look like this:
Code: |
#include <18F46K80.h>
#fuses HSH,NOWDT,BROWNOUT,PUT,NOPLLEN,SOSC_DIG,NOIESO,NOFCMEN
#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <can-18F4580.c>
|
Most of those fuses are absolutely essential.
Note, it also works with the line below for the CAN bus driver, I think
because we're not using any of the ECAN capabilities for the Loopback test:
Code: |
#include <can-18xxx8.c>
|
3. Comment out the two lines shown below, and substitute the new
initialization lines shown after them:
Code: |
// int1 tx_rtr=1;
// int1 tx_ext=0;
int1 tx_rtr=0; // *** Changed to 0
int1 tx_ext=1; // *** Changed to 1
|
4. Add the line for Loopback mode right after the can_init() line, as
shown below:
Code: |
can_init();
can_set_mode(CAN_OP_LOOPBACK); // *** Add this line
|
5. Add a 4.7K pull-up resistor (to the PIC's Vdd voltage) on the CANRX
pin (Pin B3) of the PIC. This is essential for loopback mode. If you
have a CAN bus driver chip such as the MCP2551 connected to the
CANTX and CANRX pins, this will also make it work. In that case, you
don't need the pull-up.
6. I also changed the data to sequential numbers instead of 0's, by
adding the lines shown below to initialize the out_data[] array:
Code: |
if ( can_tbe() && (ms > 2000))
{
ms=0;
out_data[0]= 0; // *** Add these 8 lines
out_data[1]= 1;
out_data[2]= 2;
out_data[3]= 3;
out_data[4]= 4;
out_data[5]= 5;
out_data[6]= 6;
out_data[7]= 7; |
Then I ran the program and got this output on the TeraTerm window
on my PC:
Quote: |
CCS CAN EXAMPLE
Running...
PUT 1: ID=24 LEN=8 PRI=3 EXT=1 RTR=0
DATA = 00 01 02 03 04 05 06 07
GOT: BUFF=0 ID=24 LEN=8 OVF=0 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 01 02 03 04 05 06 07
PUT 1: ID=24 LEN=8 PRI=3 EXT=1 RTR=0
DATA = 00 01 02 03 04 05 06 07
GOT: BUFF=0 ID=24 LEN=8 OVF=0 FILT=0 RTR=0 EXT=1 INV=0
DATA = 00 01 02 03 04 05 06 07 |
|
|
|
turhan
Joined: 24 Aug 2012 Posts: 9
|
|
Posted: Wed Aug 29, 2012 2:23 am |
|
|
I have same problem. Can you send your softwares to try it ? I gonna crazy. |
|
|
Bill24
Joined: 30 Jun 2012 Posts: 45
|
|
Posted: Wed Aug 29, 2012 6:31 am |
|
|
PCM programmer wrote: | I made Loopback mode work with a 18F46K80 with compiler vs. 4.120
in hardware (It also works with vs. 4.135). The 18F46K80 is in the same
family as your PIC so it should work for you too. I'm using a 20 MHz
crystal. |
Did you change anything in the can-18F4580.c file. E.g
can_set_id(RXFILTER0, 0, CAN_USE_EXTENDED_ID); BRGCON registers etc.
Some posts suggest register assignments for newer PIC such as the 18F46K80 are different to those in the CCS driver files.
Can you confirm if this is correct or not. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 29, 2012 1:57 pm |
|
|
turhan wrote: |
I have same problem. Can you send your softwares to try it ?
|
I posted all required changes to the Ex_Can.c file. The file is in this
CCS compiler directory:
c:\program files\picc\examples\ex_can.c
I am not going to send it to you. It's against the forum rules.
You were asked in another thread, "what is your compiler version" ?
Bill24 wrote: | Did you change anything in the can-18F4580.c file. E.g
can_set_id(RXFILTER0, 0, CAN_USE_EXTENDED_ID); BRGCON registers etc.
|
I didn't change that line. All the changes I did are listed in detail in my post.
Bill24 wrote: |
Some posts suggest register assignments for newer PIC such as the 18F46K80 are different to those in the CCS driver files.
Can you confirm if this is correct or not.
|
In the current version of the compiler, most of the #byte references to
ECAN registers in can-18F4580.h use getenv() to get the register address
from the compiler's database. So in that respect, it should work with the
18F46K80. (Assuming the database is correct in your compiler version).
But there are a few other differences between the 18F46K80 and 18F4580
that may not be handled correctly in can-18F4580.h. I am still checking
on this. But I certainly made Loopback mode work, as shown in my
earlier post. |
|
|
otaggart
Joined: 24 Aug 2012 Posts: 4 Location: Canada
|
|
Posted: Wed Aug 29, 2012 5:59 pm |
|
|
Hi,
I implemented the changes suggested by PCM Programmer to my version of EX_CAN.C (posted) and immediately had loopback mode working (using the can-18F4580.c driver). A couple more hours' work and I had three PICs communicating with each other via SN65HVD251 CAN transceivers from Texas Instruments. I appreciate your help! Some notes:
If you want to use standard ID instead of extended, set tx_ext=0 and change CAN_USE_EXTENDED_ID in can-18F4580.h to FALSE.
You can move the CAN transceiver pins from (B3RX, B2TX) to (C7RX,C6TX) by setting #FUSES CANC and changing
Code: | set_tris_b((*0xF93 & 0xFB ) | 0x08); |
in can-18F4580.c to
Code: | set_tris_c((*0xF94 & 0xBF ) | 0x80);
|
Wiring of the bus is as follows:
1) Tie all transceiver CANH pins together
2) Tie all transceiver CANL pins together
3) Connect CANH and CANL by a 120 ohm resistor at each end of the bus.
Hopefully that should help sort people out. |
|
|
Bill24
Joined: 30 Jun 2012 Posts: 45
|
|
Posted: Thu Aug 30, 2012 9:39 am |
|
|
PCM programmer wrote: |
....
In the current version of the compiler, most of the #byte references to
ECAN registers in can-18F4580.h use getenv() to get the register address
from the compiler's database. So in that respect, it should work with the
18F46K80. (Assuming the database is correct in your compiler version).
But there are a few other differences between the 18F46K80 and 18F4580
that may not be handled correctly in can-18F4580.h. I am still checking
on this. But I certainly made Loopback mode work, as shown in my
earlier post. |
Comparing signals on an oscilloscope showed that the transceiver was not working properly.
So using Compiler 4.135 and a 18F46K80 is working and verified on a PIC CAN Analyser with only the modifications listed by PCM programmer above.
Thanks everyone. |
|
|
turhan
Joined: 24 Aug 2012 Posts: 9
|
|
Posted: Mon Sep 10, 2012 3:39 am |
|
|
Bill24 did you solve this canbus problem ? Please put on website |
|
|
turhan
Joined: 24 Aug 2012 Posts: 9
|
|
Posted: Mon Sep 17, 2012 10:01 am |
|
|
I solved this problem.
Last:
Code: |
#include <18F25K80.h>
#device adc=12
#fuses HSH,NOWDT,BROWNOUT,PUT,NOPLLEN,SOSC_DIG,NOIESO,NOFCMEN,CANB
#use delay(clock=20M)
#include <can-18F4580.c>
|
Compiler version should be 4.128
oscillator =20MHZ |
|
|
|