![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 29, 2010 12:59 pm |
|
|
I was able to make it work with my test program and my test boards.
I used 18F2580 PICs because I don't have two 18F4580's. But they are
in the same PIC family. I don't have your CAN bus transceiver chips so
I used MCP2551 chips. I used 4 MHz crystals for the PICs.
Each board has a 120 ohm resistor across CANH and CANL. There is a 3
pin cable, about 12 inches long (30 cm) connecting CANH to CANH, CANL
to CANL, and ground to ground, between the two boards.
I compiled the program below with vs. 4.112 (your version). First I made
the .HEX file for Board #1 and programmed it into that board. Then I
commented out the "#define BOARD1 1" statement and re-compiled it,
and programmed it into board #2.
I connected the RS-232 serial port on Board #1 to my PC, and loaded
TeraTerm, running at 9600 baud.
I disconnected the ICD2 cable after programming and pressed the Reset
button on both boards. Then I started typing into TeraTerm and it worked.
Local echo is "off" on TeraTerm, so it's actually working. Here's what I
typed and got back. This is copied and pasted from TeraTerm.
Quote: |
Now is the time for all good men.........
|
I think you should get another one of your boards, and connect them
together, and try this test. Here are the cable connections between
the boards:
Code: | rs232 CAN
PC <-----> Board1 <---> Board2
|
I didn't edit the can-18F4580.c or can-18F4580.h files at all. They are
fresh files from the install of PCH vs. 4.112 that I did a few minutes ago.
Code: |
#include <18F2580.h>
#fuses XT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <can-18F4580.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
} |
|
|
![](templates/subSilver/images/spacer.gif) |
LMS_EE
Joined: 27 Oct 2010 Posts: 9 Location: Georgia VT
|
|
Posted: Mon Nov 01, 2010 9:27 am |
|
|
Hey PCM
Thanks for the step in the right direction. Can you do me a favor when you get a chance and see if you can see canbus output messages on the TX pin of the first MCU when you send it an RS232 command? Can you see the messages when the second MCU is not connected to the first one?
Thanks! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 01, 2010 1:43 pm |
|
|
I used the program that I posted earlier, and compiled it for "Board #1"
and programmed it into the test board. This test is done with Board #1
only. It is not connected to Board #2. It just has the PIC, and MCP2551
and the 120 ohm terminator resistor. It's just one board by itself.
Initially, the TXD pin (pin 1) on the MCP2551 is at a high level (+5v).
I then pressed the Enter key on the PC, while running TeraTerm.
The TXD pin now has constant activity. It has pulses for 2.6ms, then
a high level for 1ms, and then repeats the same pattern constantly.
The RXD pin has the same pattern and levels as the TXD pin.
For the CANH pin, it was sitting at +2.5v initially. When I press the Enter
key once, it puts out constant activity, the same pattern as the above,
but voltage levels are from 2.5v to 3.5v.
For the CANL pin, it was also sitting at +2.5v initially. Whe I pressed Enter
it put out the same constant activity pattern, but with voltage levels from
1.5v to 2.5v. |
|
![](templates/subSilver/images/spacer.gif) |
parchao
Joined: 08 Jan 2011 Posts: 3
|
problems board2 |
Posted: Sat Jan 08, 2011 11:32 am |
|
|
hi
I am working with an internal oscillator with pic18f4585 8MHz. I like to know how to set the baud rate since the Board2 does not enter the first function
if(can_kbhit()==true) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 08, 2011 2:53 pm |
|
|
The CAN bus baud rate is set by the can_set_baud() function, which
is called by can_init().
This thread explains how to use the MBTime program to calculate the
values for can_set_baud():
http://www.ccsinfo.com/forum/viewtopic.php?t=22138
It also has a link to download the MBTime program. |
|
![](templates/subSilver/images/spacer.gif) |
parchao
Joined: 08 Jan 2011 Posts: 3
|
problems continued |
Posted: Thu Jan 13, 2011 4:59 pm |
|
|
hi
I set my CAN communication accept any message because it is only way to login to the can_kbhit function () of board2.
Anyone know if you change the mode of reception does not enter the function?
I checked the values are different from those received and sent. |
|
![](templates/subSilver/images/spacer.gif) |
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
Re: problems continued |
Posted: Thu Jan 13, 2011 7:32 pm |
|
|
Umm..... HUH?!?! I know a decent amount about CANBus development for PIC chips so I will help you if I can. However, I can't make sense of what you are asking. Can you explain it again?
parchao wrote: | hi
I set my CAN communication accept any message because it is only way to login to the can_kbhit function () of board2.
Anyone know if you change the mode of reception does not enter the function?
I checked the values are different from those received and sent. |
|
|
![](templates/subSilver/images/spacer.gif) |
parchao
Joined: 08 Jan 2011 Posts: 3
|
problems continued |
Posted: Fri Jan 14, 2011 1:24 pm |
|
|
hi
I have configured the reception mode as CAN_RX_ALL and it communicates but the values from the sendings and receptions are different.
This is my problem, can anyone help?
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
Re: problems continued |
Posted: Fri Jan 14, 2011 8:43 pm |
|
|
parchao wrote: | hi
I have configured the reception mode as CAN_RX_ALL and it communicates but the values from the sendings and receptions are different.
This is my problem, can anyone help?
Thanks. |
You mean that you send certain data and when you receive it it is actually different? Could this be a result of endian issues? (That is, are you expecting least significant byte first on an int16 or int32 but really getting most significant byte first?) Can you post an example (as short as possible) of a program that causes this error? Remember that you don't have to, and in fact should not, post any CCS source code. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|