sadism04
Joined: 08 Apr 2010 Posts: 4
|
Problem to transmit and receive message via CAN |
Posted: Thu Apr 08, 2010 11:39 pm |
|
|
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. |
|