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

CAN problem with dspic30f6010A

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



Joined: 12 Aug 2011
Posts: 4
Location: Taiwan

View user's profile Send private message

CAN problem with dspic30f6010A
PostPosted: Thu Nov 24, 2011 5:09 am     Reply with quote

Hi everyone. I'm using dspic30f6010a with 10Mhz, and I set the Bit rate 500K. Now I encounter some problem that I can transmit data but not receive data. The following is my code. Could someone tell me how to modify.Thanks a lot. It never entered into can_kbhit().
Code:

   #include <30F6010A.h>
#fuses EC
#device *=16 ADC=12
#use delay(clock=10Mhz)

  can_init();
  can_set_mode(CAN_OP_CONFIG);   //must be in config mode before params can be set
//設定can baud rate 500k
   C1CFG1.brp=CAN_BRG_PRESCALAR;
   C1CFG1.sjw=CAN_BRG_SYNCH_JUMP_WIDTH;

   C1CFG2.prseg=CAN_BRG_PROPAGATION_TIME;
   C1CFG2.seg1ph=CAN_BRG_PHASE_SEGMENT_1;
   C1CFG2.sam=CAN_BRG_SAM;
   C1CFG2.seg2phts=CAN_BRG_SEG_2_PHASE_TS;

   C1CFG2.seg2ph=CAN_BRG_PHASE_SEGMENT_2;
   C1CFG2.wakfil=CAN_BRG_WAKE_FILTER; 
//設定can 中斷
   enable_interrupts(INT_CAN1);
   can_enable_interrupts(RX0 | RX1 );
   enable_interrupts(INTR_GLOBAL);

   can_set_mode(CAN_OP_NORMAL);
   can_putd(0x280,CAN_data,8,3,FALSE,FALSE);
   printf("Running...........\n");
 while(1)
   {

     if ( can_kbhit() )   //if data is waiting in buffer...
         {
          if(can_getd(rx_id, &buffer[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 ",buffer[i]);
            }
            printf("\r\n");
            if (rx_id == 300) {
               printf("GET DATA\r\n\r\n");
            }
         }
      }
}
mitice



Joined: 12 Aug 2011
Posts: 4
Location: Taiwan

View user's profile Send private message

PostPosted: Wed Nov 30, 2011 12:11 am     Reply with quote

I try to operate in loop-back mode. It still didn't get the can message.
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