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

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



Joined: 23 Aug 2008
Posts: 24
Location: Italy

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

CAN data corrupt
PostPosted: Sat Aug 23, 2008 8:08 am     Reply with quote

Hello,
I built a circuit with a 18lf2680 and Texas SN65HVD1040DR (the equivalent of MCP2551) to test the CAN bus at 50kbps. The board uses the internal oscillator @8MHZ and is connected to a LAWICEL CANUSB device (www.canusb.com).
I have the two 120ohm resistors in place.
I made a test project with the useful project wizard so the compiler selected the best parameters for the bus.
I see a strange behavior: the CAN monitor on my pc receives packets with the correct address but the data is completely different.
I tried both 29 and 11 bit identifiers, but the result is the same: I get 2 alternating set of data...

but the array that I write is always the same:
Code:

CCS CAN EXAMPLE

Running...
PUT 1: ID=2645 LEN=8 PRI=3 EXT=0 RTR=1
   DATA = 01 02 03 04 05 06 07 08

PUT 1: ID=2645 LEN=8 PRI=3 EXT=0 RTR=1
   DATA = 01 02 03 04 05 06 07 08

I also tried to change manually the config registers, following PCM programmer's GREAT guide, but the result is the same.
Code:

   BRGCON1 = 0x07;
   BRGCON2 = 0xA1;
   BRGCON3 = 0x01;

Also the Address is received correctly, so I think my timing is correct (I tried with 0x55, so it is 01010101 and I can spot errors easily).
Do you have any suggestion?
Also, another question: this will be a battery powered device, and it must have very low power consumption. Is the CAN bus the right choice? The bus length will be about 80mt, and the anti collision will allow me to do some nice tricks. Will the module receive messages also when the PIC is sleeping, and wake him up? It needs the main clock, right?

Thank you very much
Cristiano
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 11:17 pm     Reply with quote

Try running the PIC board with the CAN bus in Loopback mode.
Disconnect the Lawicel CANUSB device, and just connect the PIC board
to the PC with a RS-232 connection:
http://www.ccsinfo.com/forum/viewtopic.php?t=20106

In the middle of this thread, there is a test program for two PIC boards,
with a CAN bus connection on each board. This code will test if the two
PIC boards can talk to each other correctly through the CAN bus.
http://www.ccsinfo.com/forum/viewtopic.php?t=29627

Both of these tests display the result in a terminal window on the PC.
The connection to the PC is made by RS-232. The reason for this
is because maybe your Lawicel CANUSB device and software don't work,
or the configuration of the software is incorrect. By using the tests
above, you can test your PIC board without using the Lawicel CANUSB
device.
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

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

PostPosted: Wed Aug 27, 2008 10:37 am     Reply with quote

Thank you PCM! IT WORKS!
I'm very happy, and I surely own you a beer.

I first tried in loopback mode, with the code you supplied, and it worked. Then I commented the loopback mode line.... And the CANUSB read it correctly!

Turns out, the example from CCS uses this line for sending data:
Code:

i=can_putd(tx_id, &out_data[0], tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer


Well, I didn't notice that at the tx_ext variable was declared as 0... But on the second link you posted, they say that the standard init function works only with EXT IDs!!! Does CCS test their code before publishing? The Fat16 library didn't even compile because of a typo... After correcting it, it worked like a charm! Very Happy

Do you have any suggestion on the other questions?
Quote:

Also, another question: this will be a battery powered device, and it must have very low power consumption. Is the CAN bus the right choice? The bus length will be about 80mt, and the anti collision will allow me to do some nice tricks. Will the module receive messages even when the PIC is sleeping, and wake him up? It needs the main clock, right?
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