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

Reception on CAN

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sultan



Joined: 31 Jan 2012
Posts: 8

View user's profile Send private message

Reception on CAN
PostPosted: Tue Jan 31, 2012 11:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 01, 2012 6:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 01, 2012 7:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 01, 2012 7:54 am     Reply with quote

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

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

PostPosted: Wed Feb 01, 2012 8:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 01, 2012 8:29 am     Reply with quote

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

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

PostPosted: Wed Feb 01, 2012 8:57 am     Reply with quote

So the speed is the same... maybe it's a filter problem. do you use extended IDs?
Sultan



Joined: 31 Jan 2012
Posts: 8

View user's profile Send private message

PostPosted: Wed Feb 01, 2012 9:49 am     Reply with quote

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

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

PostPosted: Wed Feb 01, 2012 2:00 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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