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 CCS Technical Support

Can Bus ID
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

Can Bus ID
PostPosted: Mon Aug 23, 2010 12:17 pm     Reply with quote

Hi everybody. I'm new in ccs forum. My project is CAN bus test. I'm trying to test node A pic18f458 and node B MCP25050 with Ex_can_a.c in ccs library but I don't know how to find ID of each node?
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

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

Re: Can Bus ID
PostPosted: Mon Aug 23, 2010 12:47 pm     Reply with quote

whazzzupp wrote:
Hi everybody. I'm new in ccs forum. my project is can bus test. I'm trying to test node A pic18f458 and node B MCP25050 with Ex_can_a.c in ccs library but I don't know how to find ID of each node?


What compiler version? I don't have a "Ex_can_a.c" file but I do have a "Ex_Can_CCS_A.c" file. Is that what you are referring to?

Generally you set the ID you want for each node. To help you find what the code is using look to the first parameter to can_putd (or can_getd).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 23, 2010 12:52 pm     Reply with quote

The ID's are in the #define statements in this file:
Quote:
c:\program files\picc\examples\ex_can_ccs_a.c

Look for the 5 #define statements that have constants with "ID" in their
names. They will have ID's such as 0x201, 0x202, etc.
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 23, 2010 10:05 pm     Reply with quote

Sorry about that. Yes, I mean Ex_Can_CCS_A.c
In section #DEFINE I see but why my controller know ID in each node and how do I can define.

EX. I have 2 node A and B
node A pic1f458 and can transceive
node B can transceive, mcp25050, 7-segment

what the ID of node B
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

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

PostPosted: Tue Aug 24, 2010 5:03 am     Reply with quote

One thing you have to keep in mind is that the ID field of a CANBus packet is somewhat misleading. It *CAN* be used as a straight ID but sometimes (ok, many times) part of the ID field will be used for other things such as which function or parameter is being sent/requested.

In that file you have two defines. One is 0x201 and one is 0x202. Node B should respond to both. In a way you could say that the ID of node B is 0x0200 and the last digit is a function code that tells node B which function it should perform. So if node B sees an ID of 0x201 it will get the A/D reading and send it back. If it sees an ID of 0x202 it will change it's LEDs. This all is facilitated by setting the canbus transceiver at the node B end to have a mask of 0x3F0 and a filter of 0x200. This will allow any packet through that is of the form 0x20? where ? could be any hex digit.

You seem to want to modify the ccs example to actually work with a MCP25050 I/O expander instead of the normal node B it's expecting. To do that you'll have to read the chip documentation for the MCP25050 and figure out how to either: 1. Set it so that it responds to the commands from the CCS example or 2. modify the CCS example to send the proper data format for the MCP25050. This is up to you, not me or PCM programmer. We can give you help if you have a specific question during coding. But, try it yourself. You'll learn a lot by just trying.

Here is the technical doc for the chip in case you need it:
http://ww1.microchip.com/downloads/en/DeviceDoc/21664D.pdf
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 24, 2010 5:41 am     Reply with quote

Thank for help. I will reading datasheet and try again.
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 24, 2010 8:32 am     Reply with quote

this code
Code:
#include <18f458.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define CAN_DO_DEBUG 1
#define CAN_ENABLE_DRIVE_HIGH  1

#include <can-18xxx8.c>

#define B_ID 0x200

void write_7_segment(int value) {
const int lcd_seg[10]={0x40,0x79,0x24,0x30,0x19,
0x12,0x02,0x78,0x00,0x10};
int buffer[3];

buffer[0]=0x1E; //addr of gplat
buffer[1]=0x7F; //mask
buffer[2]=lcd_seg[value];
can_putd(B_ID, buffer, 3, 1, TRUE, FALSE);
}

void main() {
int i=0;

can_init();

can_putd(0x100,0,0,1,TRUE,FALSE); //send an on-bus message to wake up mcp250x0's
delay_ms(1000); //wait for node c to power-up

while(TRUE) {
write_7_segment(i);
delay_ms(1000);
if(++i==10)
i=0;
}
}


why hyperterminal display only 3 buffer ?, my hardware doesn't recieve
data and display?

CAN_PUTD(): BUFF=0 ID=00000100 LEN=0 PRI=1 EXT=1 RTR=0

CAN_PUTD(): BUFF=1 ID=00000200 LEN=3 PRI=1 EXT=1 RTR=0
DATA = 1E 7F 40

CAN_PUTD(): BUFF=2 ID=00000200 LEN=3 PRI=1 EXT=1 RTR=0
DATA = 1E 7F 79

CAN_PUTD() FAIL: NO OPEN TX BUFFERS
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

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

PostPosted: Tue Aug 24, 2010 8:59 am     Reply with quote

whazzzupp wrote:

why hyperterminal display only 3 buffer ?, my hardware doesn't recieve
data and display?

CAN_PUTD(): BUFF=0 ID=00000100 LEN=0 PRI=1 EXT=1 RTR=0

CAN_PUTD(): BUFF=1 ID=00000200 LEN=3 PRI=1 EXT=1 RTR=0
DATA = 1E 7F 40

CAN_PUTD(): BUFF=2 ID=00000200 LEN=3 PRI=1 EXT=1 RTR=0
DATA = 1E 7F 79

CAN_PUTD() FAIL: NO OPEN TX BUFFERS


The PIC hardware really does only have three transmit buffers. Well, it has more but you are presumably using legacy mode where there are two receiver and three transmitter buffers. Your problem is that nothing is acknowledging the CANBus frames you are sending. You see, on the CANBus some other node must ack your frame otherwise it will not leave your transmit buffer. In fact, the hardware will repeatedly try to resend the first frame in the buffer over and over. So, figure out why your other node is not acknowledging frames. Maybe your wiring is bad, maybe the 25050 chip is not initialized correctly, maybe you've got a bad baud rate set on one end or the other.

I did notice that you are sending the frames as extended frames even though your ID is a standard ID. You might want to set ext to 0. I'm almost positive that this issue wouldn't have caused your trouble though. The hardware should acknowledge regardless.
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 24, 2010 9:45 am     Reply with quote

Thank a lot for your help. I'm using nomal mode and try to change ext = 0
ิีbut hyperterminal is display it same.

And I have a problem about legacy mode. I think legacy is mode of ECAN.
If I change, what mode I change to? and where I can change?
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

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

PostPosted: Tue Aug 24, 2010 10:16 am     Reply with quote

whazzzupp wrote:
Thank a lot for your help. I'm using nomal mode and try to change ext = 0
ิีbut hyperterminal is display it same.

And I have a problem about legacy mode. I think legacy is mode of ECAN.
If I change, what mode I change to? and where I can change?


Legacy is indeed a mode of the ECAN module. The other two common modes are enhanced and enhanced fifo. Don't change the mode unless you really have to. I've had troubles with the enhanced modes. I think there might be a compiler bug or an oddity in the canbus driver source code or something. If you insist on changing it then it's set near the top of can_init. You want to find curfunmode=CAN_FUN_OP_LEGACY; and set it to CAN_FUN_OP_ENHANCED or CAN_FUN_OP_ENHANCED_FIFO.

What you really want to do is verify that your wiring between nodes is correct and that you have the necessary transceiver modules (you cannot just hook the PIC chip directly up to the canbus!) After that make sure your baud rate is correct and the same for all nodes.
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 24, 2010 12:03 pm     Reply with quote

Between CANH and CANL I use 240 ohm instead 120 ohm. Do you think
it cause to hardware doesn't display output.
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

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

PostPosted: Tue Aug 24, 2010 12:22 pm     Reply with quote

whazzzupp wrote:
Between CANH and CANL I use 240 ohm instead 120 ohm. Do you think
it cause to hardware doesn't display output.


Usually CANBus is very tolerant of improper termination resistors but it's possible. It depends on the distance, the quality of the wire, etc. Remember, you should have resistors on both ends of the canbus. Typically people use 120 ohms of resistance on both ends thus the bus itself would have a nominal 60 ohms resistance.

There are two ways to know for sure:

1. Use an oscilloscope and see if you are getting crisp transitions between voltage levels. You want to see a clean square pattern not ramps up and down or random noise. Additionally the high and low lines should switch between meeting in the center and moving equal distances apart.
2. Use the proper resistors and see if it magically starts working.

And, once again, if that doesn't yield any solutions, be sure you have the baud rates set right. Your problem will also happen if the two nodes are not very close in baud timing. Sometimes you have to play with your propagation time, and your seg1 and seg2 times. This is especially going to be an issue if the two nodes run off of vastly different clock sources. For instance, it might be tough to match timings between a 20MHz pic and a 8Mhz node at the other end. You can tweak your bit timings within the canbus driver's header file. It's pretty well documented.
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 25, 2010 5:53 am     Reply with quote

Can you give me a Program for programming mcp250xx. My program MCP250xx Programmer v.1.1.0 from Microchip is error. Can I use another program ?
MikeW



Joined: 15 Sep 2003
Posts: 184
Location: Warrington UK

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 6:01 am     Reply with quote

you do realise that the mcp250xx is NOT reprogrammable.

you cannot reprogram the ones from CCS , you must obtain blank ones.

I gave up on trying to program them, I just kept programming them, then they wouldnt work, then throwing them in the bin.

I wish Microchip would update them to flash parts.

Mike
whazzzupp



Joined: 23 Aug 2010
Posts: 11

View user's profile Send private message Send e-mail

PostPosted: Wed Aug 25, 2010 1:35 pm     Reply with quote

I can export file .hex from MCP250xx Programmer and write to MCP25050 by pickit2 ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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