View previous topic :: View next topic |
Author |
Message |
Sultan
Joined: 31 Jan 2012 Posts: 8
|
Reception on CAN |
Posted: Tue Jan 31, 2012 11:26 pm |
|
|
Hi. I need help regarding CAN communication using PIC 18F4680. I have used library developed for CAN prototype board. I have used example EX_CAN but nothing was received. I am sending data through CAN analyzer. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1935 Location: Norman, OK
|
|
Posted: Wed Feb 01, 2012 6:21 am |
|
|
What compiler version?
Show us your code (do not show the CCS library code), just show
where it was included. I just finished several CAN projects with the
library and it worked with no problems. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Sultan
Joined: 31 Jan 2012 Posts: 8
|
|
Posted: Wed Feb 01, 2012 7:36 am |
|
|
Hi. Following is the code
Code: |
#include <18F4680.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <can-18xxx8.c>
void main() {
struct rx_stat rxstat;
int32 rx_id;
int in_data[8];
int rx_len;
int i;
for (i=0;i<8;i++) {
in_data[i]=0;
}
can_init();
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");
}
}
}
}
|
I transmit data on CAN through Microchip CAN analyzer toolkit. I send 8 bytes of data periodically after every 2 sec. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1935 Location: Norman, OK
|
|
Posted: Wed Feb 01, 2012 7:54 am |
|
|
What baud rate is the CAN analyzer transmitting? The library defaults to 125K _________________ Google and Forum Search are some of your best tools!!!! |
|
|
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
|
Posted: Wed Feb 01, 2012 8:27 am |
|
|
I would also suggest you to try the opposite too, check if the PIC can send data on the CAN bus! |
|
|
Sultan
Joined: 31 Jan 2012 Posts: 8
|
|
Posted: Wed Feb 01, 2012 8:29 am |
|
|
Hi
I have done the opposite. PIC is sending data on CAN bus which can be monitored through CAN analyzer. |
|
|
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
|
Posted: Wed Feb 01, 2012 8:57 am |
|
|
So the speed is the same... maybe it's a filter problem. do you use extended IDs? |
|
|
Sultan
Joined: 31 Jan 2012 Posts: 8
|
|
Posted: Wed Feb 01, 2012 9:49 am |
|
|
Hi
Transmission baud rate is 125K . I haven't changed defaults of can_init function in can-18xxx8.c. I assume the line
can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID); //set mask 0
means it will accept transmission from all IDs. I am sending data from ID 20, 24 ,21. Neither of them worked. Am I supposed to change any mask or filters? |
|
|
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
|
Posted: Wed Feb 01, 2012 2:00 pm |
|
|
Mh, 20, 24 and 21 are small, are you using short IDs? You could try to delete the " CAN_USE_EXTENDED_ID" part and see what happens. |
|
|
|