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

Problem to transmit and receive message via CAN

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



Joined: 08 Apr 2010
Posts: 4

View user's profile Send private message

Problem to transmit and receive message via CAN
PostPosted: Thu Apr 08, 2010 11:39 pm     Reply with quote

I have 2 PIC18f458 and want one is transmitter and another is receiver.

Transmitter
Code:

void main(void)
{
   out_data[0] = 0x11 ;
   out_data[1] = 0xCC ;
   out_data[2] = 0x33 ;
   out_data[3] = 0xEE ;
   out_data[4] = 0x55 ;
   out_data[5] = 0xAA ;
   out_data[6] = 0x77 ;
   out_data[7] = 0xFF ;
   can_init() ;

   printf("\n\n\r *** CAN Master *** ") ;

   while(1)
   {
      printf("\n\n\rPress Enter to Sent Message") ;
      c = getch() ;

      if(can_putd(tx_id ,out_data ,tx_len ,tx_pri ,tx_ext ,tx_rtr))
      {
         printf("\n\rMessage is Transmitting\n") ;
         for(i=0;i<8;i++)
            printf("%x ",out_data[i] ) ;
         printf("\n\r") ;
      }
      else
         printf("\n\rSent Message Error") ;

   }
}


Receiver
Code:

void main(void)
{
   struct rx_stat rxstat ;
   int32 rx_id ;
   int rx_len ;
   int in_data[8] ;
   int i ;

   can_init() ;
   enable_interrupts(GLOBAL) ;

   for(i=0;i<8;i++)
      in_data[i] = 0 ;

   printf("\n\n\r *** CAN Slave *** " ) ;

   while(1)
   {
     if(can_kbhit() )
     {
      printf("\n\rGet Message in Buffer") ;

      if(can_getd(rx_id ,in_data ,rx_len ,rxstat ))
      {
         printf("\n\rShow ID : %LU",rx_id ) ;
         for(i=0;i<8;i++)
            printf("%x ",in_data[i] ) ;
         printf("\n\r") ;
      }
     
     }

   }
}

When I test them, transmitter send message. It shows "Message is Transmitting" but receiver haven't respond.
Can anyone solve my problem?

I'm a newbie and not good in english.

Thank for all reply.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 09, 2010 12:54 am     Reply with quote

Use the code in this post. It shows how to test the CAN bus connection
between two 18F458 boards:
http://www.ccsinfo.com/forum/viewtopic.php?t=29627&start=7

Use this schematic:
http://www.microchip.com/forums/upfiles.aspx/52252/1E05A177D4B746B0B4C23DB18CC4F360.JPG
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