|
|
View previous topic :: View next topic |
Author |
Message |
arunraja
Joined: 05 Dec 2007 Posts: 2
|
can in normal mode |
Posted: Wed Dec 05, 2007 11:22 pm |
|
|
hi,
i try to establish can communication between two 18f2480 controllers. i kept them on two seperate boards with MCP2551 as can driver. when i checked it with EX_CAN.C code with loop back mode, both the controllers work fine. but when i changed to normal mode with one as transmitter and other as receiver, the message is transmitted, but not received by other node.
here is my transmitter code,
#define CAN_ENABLE_DRIVE_HIGH 1
#include <18F2480.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <can-18xxx8.c>
int16 ms;
#int_timer2
void isr_timer2(void) {
ms++; //keep a running timer that increments every milli-second
}
void main() {
//send a request (tx_rtr=1) for 8 bytes of data (tx_len=8) from id 24 (tx_id=24)
char out_data[9]={"ARUNRAJA"};
int32 tx_id=24;
int1 tx_rtr=0;
int1 tx_ext=1;
int tx_len=9;
int tx_pri=3;
int i,j;
printf("\r\n\r\nCCS CAN EXAMPLE\r\n");
setup_timer_2(T2_DIV_BY_4,79,16); //setup up timer2 to interrupt every 1ms if using 20Mhz clock
// port_b_pullups(TRUE);
can_init();
enable_interrupts(INT_TIMER2); //enable timer2 interrupt
enable_interrupts(GLOBAL); //enable all interrupts (else timer2 wont happen)
printf("\r\nRunning...");
while(TRUE)
{
//every ten seconds, send new data if transmit buffer is empty
if ( can_tbe() && (ms > 10000))
{
ms=0;
i=can_putd(tx_id, out_data, tx_len,tx_pri,tx_ext,tx_rtr); //put data on transmit buffer
if (i != 0xFF) { //success, a transmit buffer was open
printf("\r\nPUT %U: ID=%LU LEN=%U ", i, tx_id, tx_len);
printf("PRI=%U EXT=%U RTR=%U\r\n DATA = ", tx_pri, tx_ext, tx_rtr);
for (j=0;j<tx_len;j++)
{
printf("%X ",out_data[j]);
}
printf("\r\n");
}
else { //fail, no transmit buffer was open
printf("\r\nFAIL on PUTD\r\n");
}
}
}
}
the receiver code,
#include <18F2480.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include<can-18xxx8.c>
char out_data[9]={"ARUNRAJA"};
int16 ms;
#int_timer2
void isr_timer2(void) {
ms++; //keep a running timer that increments every milli-second
}
void main() {
struct rx_stat rxstat;
int32 rx_id;
int in_data[8];
int rx_len;
int32 tx_id=24;
int1 tx_rtr=0;
int1 tx_ext=1;
int tx_len=9;
int tx_pri=3;
int i;
for (i=0;i<9;i++)
{
in_data[i]=0;
//out_data[i]=0;
}
printf("\r\n\r\nCCS CAN EXAMPLE\r\n");
setup_timer_2(T2_DIV_BY_4,79,16); //setup up timer2 to interrupt every 1ms if using 20Mhz clock
//port_b_pullups(TRUE);
can_init();
enable_interrupts(INT_TIMER2); //enable timer2 interrupt
enable_interrupts(GLOBAL); //enable all interrupts (else timer2 wont happen)
printf("\r\nRunning...");
while(TRUE)
{
if ( can_kbhit() ) //if data is waiting in buffer...
{
if(can_getd(rx_id, &in_data[0], rx_len, rxstat)) { //...then get data from buffer
printf("\r\nGOT: BUFF=%U ID=%LU LEN=%U OVF=%U ", rxstat.buffer, rx_id, rx_len, rxstat.err_ovfl);
printf("FILT=%U RTR=%U EXT=%U INV=%U", rxstat.filthit, rxstat.rtr, rxstat.ext, rxstat.inv);
printf("\r\n DATA = ");
for (i=0;i<rx_len;i++) {
printf("%X ",in_data[i]);
}
printf("\r\n");
}
else {
printf("\r\nFAIL on GETD\r\n");
}
}
}
}
should i have to make any modification in this code? Please help me to find the bug.
thank you,
Arunraja |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
arunraja
Joined: 05 Dec 2007 Posts: 2
|
still problem continues |
Posted: Sat Dec 08, 2007 6:31 am |
|
|
dear PCM,
i am using baud rate set by the ccs driver,
i am using MCP2551 as can transceiver,
the boards i built by my self, with 120ohm in each transceiver ends,
the version i am using is CCS PCH V4.
i checked with those forums, and i changed the header file can-18xxx8.c to can-18f4580.c,
still i can't be able to communicate with my two PICs
(even the test program doesn't work),
help me if i have to make any changes in my code.
regards,
arunraja |
|
|
jma_1
Joined: 08 Feb 2005 Posts: 147 Location: Wisconsin
|
|
Posted: Sat Dec 08, 2007 10:38 am |
|
|
Greetings Arunraja,
It would be easier to look at the code you posted if you use the code tags.
Perhaps a bus monitoring tool will assist you in debugging. If the message is transmitted, the bus tool should be able to capture it. This will allow you to verify the bus speed, data bytes, etc. The tool should also allow you to send messages to the receiver (independently verify operation of the receiver hardware and software). Two very inexpensive tools are listed below.
http://www.easysync-ltd.com/index.html?lang=en-uk&target=d20.html
http://canpic.com/
Cheers,
JMA |
|
|
|
|
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
|