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 support@ccsinfo.com

CAN on the 18F4680

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



Joined: 22 Mar 2006
Posts: 2

View user's profile Send private message

CAN on the 18F4680
PostPosted: Wed Mar 22, 2006 2:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 22, 2006 7:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 22, 2006 9:49 am     Reply with quote

What's the part number of the CAN bus transceiver chip
that you're using ?
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Wed Mar 22, 2006 11:28 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 31, 2006 9:40 am     Reply with quote

"#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: 1903

View user's profile Send private message

PostPosted: Fri Mar 31, 2006 11:40 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 31, 2006 10:35 pm     Reply with quote

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
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