View previous topic :: View next topic |
Author |
Message |
sholto
Joined: 22 Mar 2006 Posts: 2
|
CAN on the 18F4680 |
Posted: Wed Mar 22, 2006 2:53 am |
|
|
I am using PCWH 3.236 via ICD-U40 on a 18F4680.
The CAN drivers provided with the compiler don't seem to work. There is no output from the Tx pin on the device.
I wrote some of my own routines. In loopback mode the data transfers correctly from Tx to Rx buffers.
Additionally I now get a CAN packet out of the Tx pin at the correct baud rate.
However it is all zeros despite the data registers showing as loaded with valid data. The only transitions I see on a CRO are the CAN state changes to maintain clock sync.
Is there some starnge register somewhere that needs to be enabled particularly for this device? Here's what I did.
can_set_mode(CAN_OP_CONFIG);
BRGCONn set to 125Kb/s
CIOCON.endrhi = pull Tx high;
CIOCON.cancap = enable receive;
ECANCON.mdsel=fifo;
BSEL0 = make all RX/TX buffers RX;
can_set_mode(CAN_OP_NORMAL);
Fill the TXB0 address's and set it to extendedid.
Fill the TXB0 buffer data and set data length (8);
Set TXB0CON priority to 3;
Set the TxRequest bit for only TXB0CON;
I now see an all zeros CAN packet at the right baud rate.
Regards,
Sholto Weir. |
|
|
jma_1
Joined: 08 Feb 2005 Posts: 147 Location: Wisconsin
|
|
Posted: Wed Mar 22, 2006 7:47 am |
|
|
Greetings,
You mentioned the compiler examples do not work. I do not have the same compiler version and the latest example files. The CAN-18xx8 example file perhaps needs to be tweaked for the part which you are using? One troubleshooting suggestion might be to try and get the example code working correctly with your part or see if there updated examples.
Cheers,
JMA |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 22, 2006 9:49 am |
|
|
What's the part number of the CAN bus transceiver chip
that you're using ? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Wed Mar 22, 2006 11:28 am |
|
|
PCM programmer wrote: | What's the part number of the CAN bus transceiver chip
that you're using ? |
I had issues when I first started playing with CAN too. I didn't use the 18F4680 though.
I used the LT1796 transceivers, and the transmit always seemed to be dead. PCM finally traced the problem (thanks again) to an erroneous define in "can-18xxx8.h".
Find this line:
Code: | #ifndef CAN_ENABLE_DRIVE_HIGH
#define CAN_ENABLE_DRIVE_HIGH 0
#endif |
It's wrong. It should be 1, not 0. The fix is to put this:
Code: | #define CAN_ENABLE_DRIVE_HIGH 1 |
just before the you include "can-18xxx8.c"
Of course, this only applies if you're using the LT1796's. They do not have pullups on the TX in line from the PIC, so the PIC has to be able to drive that line high.
I informed CCS of this issue in August (or maybe July?) and I still haven't had a reply. They didn't fix it yet either. |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri Mar 31, 2006 9:40 am |
|
|
"#define CAN_ENABLE_DRIVE_HIGH 0" is correct for the Microchip 2551 transceiver. Given that you're using Microchip PICs, defaulting to a configuration for the Microchip CAN transceiver seems quite appropriate to me, and not a bug at all.
As you've noticed, if you use a different transceiver, the CCS code is designed to allow their defaults to be overridden as required... _________________ Andrew |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Fri Mar 31, 2006 11:40 am |
|
|
andrewg wrote: | "#define CAN_ENABLE_DRIVE_HIGH 0" is correct for the Microchip 2551 transceiver. Given that you're using Microchip PICs, defaulting to a configuration for the Microchip CAN transceiver seems quite appropriate to me, and not a bug at all.
As you've noticed, if you use a different transceiver, the CCS code is designed to allow their defaults to be overridden as required... |
It is a bug. Look for PCM's post at the bottom of the first page:
http://www.ccsinfo.com/forum/viewtopic.php?t=23825&highlight=canenabledrivehigh |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri Mar 31, 2006 10:35 pm |
|
|
I think I see your point. I didn't see any problems because it all worked for me "out of the box". Driving high would still work with the MCP2551, but also allow transceivers like the LT1796 which don't have pullups to also work without needing to override the default. _________________ Andrew |
|
|
|