View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 30, 2007 12:51 pm |
|
|
Try to make each node work separately in Loopback mode.
See the following thread for sample code.
http://www.ccsinfo.com/forum/viewtopic.php?t=20106
If you can get each node to work in loopback mode, it will
prove that each PIC is running OK, and the CAN module is
working, and that the compiler generates good code. |
|
|
quad3
Joined: 23 Jan 2007 Posts: 5
|
|
Posted: Tue Jan 30, 2007 6:50 pm |
|
|
the 2 nodes work fine separately. i've tried the loopback mode on each node |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 30, 2007 9:06 pm |
|
|
I have a couple 18F458 boards. I can test it Wednesday morning.
Edited to add:
I can do it on Sunday. I got the two boards out of the storage closet
and made power supply adapters for them, so I can use them.
I can't commit any more time to it during the week.
--------
Last edited by PCM programmer on Thu Feb 01, 2007 2:53 pm; edited 1 time in total |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Wed Jan 31, 2007 5:59 am |
|
|
Have a look at:
http://www.ccsinfo.com/forum/viewtopic.php?t=29646
NOTE TO FORUM MODERATORS:
If guests (non registered members) were stopped from posting and forced to register, then quad3 could PM the guest on the thread in the link above and between them they could sort this out !! Isn't that what forums are all about ?! _________________ Regards,
Simon. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 04, 2007 5:15 pm |
|
|
Here is a simple test program which allows you to prove that two CAN
boards can talk to each other. Each board has an 18F458 PIC on it,
with an MCP2551 (or equivalent) CAN bus driver and a 120 ohm resistor
connected across the CANL and CANH pins (one on each board).
I tested this program with PCH vs. 3.249.
What this program does:
First you type in characters on a terminal window in your PC. The
chars are sent to Board #1 by an RS-232 cable. Then Board #1
transmits them to Board #2 over the CAN bus. Board #2 then
sends each character back to Board #1 over the CAN bus. Finally,
Board #1 sends them back to the PC over the serial cable. It's just
a big loop.
So when you run this program, you just open up a terminal window
on your PC, and start typing. For example, type:
You should see it appear on your terminal window. (Make sure you
have "local echo" turned off in your terminal program).
Here is the signal path that the characters follow:
Code: |
rs232 CAN CAN rs232
PC -----> Board #1 ---> Board #2 ---> Board #1 -----> PC
|
This diagram shows the cables:
Code: |
rs232 CAN
PC <-----> Board1 <---> Board2
|
The program below is in two parts. It has to be compiled separately
for each of the two CAN boards. After you compile the code for each
specific board, you must program it into the PIC on that board with
your programmer. Remember, this was only tested with PCH vs. 3.249.
The board for which the program is compiled is controlled by the
following line within the program:
If it's uncommented, the program will be compiled for Board #1.
If it's commented out, then the program will be for Board #2.
Here is the program:
Code: |
#include <18F458.h>
#fuses HS, NOPROTECT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <can-18xxx8.c>
#define BOARD1_ID 24
#define BOARD2_ID 25
// Uncomment this line to compile code for Board #1.
// Comment it out to compile for Board #2.
#define BOARD1 1
//======================================
void main()
{
struct rx_stat rxstat;
int32 rx_id;
int32 tx_id;
int8 rx_len;
int8 buffer[8];
can_init();
#ifdef BOARD1 // For Board #1
while(1)
{
buffer[0] = getc(); // Wait for a character
// Transmit it to board #2.
can_putd(BOARD2_ID, buffer, 1, 1, 1, 0);
buffer[0] = 0; // Clear the buffer byte
// Wait for the char to be echoed back.
while(!can_kbhit());
if(can_getd(rx_id, buffer, rx_len, rxstat))
{
if(rx_id == BOARD1_ID) // Is it for this board ?
{
putc(buffer[0]); // If so, display the char
}
}
}
#else // For Board #2
while(1)
{
if(can_kbhit()) // Message available ?
{
// If so, get the message.
if(can_getd(rx_id, buffer, rx_len, rxstat))
{
if(rx_id == BOARD2_ID) // Is it for this board ?
{
// If so, echo back the character.
can_putd(BOARD1_ID, buffer, 1, 1, 1, 0);
}
}
}
}
#endif
} |
|
|
|
Stephane Guest
|
#define BOARD1 1 |
Posted: Sun Jan 13, 2008 10:30 am |
|
|
Hello PCM Programmer
I'm french and there's a thing i'm not sure to understand when you wrote :
The board for which the program is compiled is controlled by the
following line within the program:
Quote:
#define BOARD1 1
If it's uncommented, the program will be compiled for Board #1.
If it's commented out, then the program will be for Board #2.
Can you tell me if i'm right if i use this for Board1 :
#define BOARD1 1
And this for Board2 :
#define BOARD1 OUT
Am i wrong ?
I will test this next week with PCWH and i'll tell you if this program work on it
Thanks
Stephane |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 13, 2008 10:33 am |
|
|
"Commented out" means to make the line into a comment by
adding the two slashes in front of it. Then the compiler will
consider the line to be a comment and it won't be compiled.
Do it this way:
Code: | // #define BOARD1 1 |
|
|
|
Stephane Guest
|
long CCP_1 |
Posted: Sun Jan 13, 2008 10:38 am |
|
|
Another question :...
When i try to compile your source code i've got a error message in the
18F448.h
A #DEVICE required before this line :
long CCP_1;
In the same file there's :
long CCP_2;
and there's no error message for this line..
if i add a #define in front of long CCP_1; another error message appears...
An idea ?
Thanks again
Stephane |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 13, 2008 10:51 am |
|
|
You are a beginner with the CCS compiler. Please take some time
to learn to use the compiler before starting a project on the CAN bus.
Learn to use the compiler. Make simple programs such as "blinking
an LED". Then when you know the compiler, you can do the CAN bus
projects. |
|
|
Stephane Guest
|
CAN |
Posted: Mon Jan 14, 2008 4:04 am |
|
|
Thank you for your rapid answer
Sorry to disturb yourself
But... i'm not a beginner on CCS...
I can play with LEDS, with the RS232 without problem..
But there are some english terms (i'm french) i do not understand
"commented OUT" is easy to understand for an english speaking person.. it may be confused for a foreign one
And some technical problems like this new one i've tried to resolve
long CCP_1; ?
Thanks for your understanding
Stephane |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 14, 2008 12:06 pm |
|
|
1. What is your compiler version ?
2. Try re-installing the compiler. See if that fixes the problem. |
|
|
Stephane Guest
|
PCWH |
Posted: Tue Jan 15, 2008 12:52 pm |
|
|
Hello
My software version : PCWH 4.058
Reinstall : the same problem.
I can't understand the error message is not in the program but in the 18F448.h file...
The program is the one you give in this topic.
I hope it will work, this will be a good beginning to work with CAN bus and CCS Compiler
Thank you again for your help
Stephane |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 15, 2008 1:03 pm |
|
|
Try this program. It blinks an LED on Pin B0. Does this program
compile with no errors ?
Code: |
#include <18F448.h>
#fuses HS, NOPROTECT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//======================================
void main()
{
while(1)
{
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
delay_ms(500);
}
} |
|
|
|
Stephane Guest
|
LEDS |
Posted: Fri Jan 18, 2008 10:31 am |
|
|
Sorry I didn't see your answer (i didn't see there was a second page)
Same error message with this little program...
Yet i have tried another simple program with leds for a 18f448 just before yours (CAN BUS) and it was OK.
... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 18, 2008 11:37 am |
|
|
I was able to duplicate your problem. I commented out the #device
statement in the 18F448.h file, and I got the error message that you get.
Example:
Quote: | // Standard Header file for the PIC18F448 device
//#device PIC18F448
#nolist |
Question:
Did you do this ? Did you comment out the #device statement ?
If so, please put it back the way it was. Never edit the .H files. |
|
|
|