Hello hello,
Part of my final internship I have to analyze CAN-BUS messages. The company has provided me with a KEIL MCB2300 (LPC2368) I have modified the original can example program from NXP (Philips) to only receive CAN data and display it on the LCD.'
Via a computer I generate a CAN message every 0.5 seconds. The message identifier is (%d) 1111 and the data varies.
*problem* After receiving between 10 and 20 messages the program jams but some times it stops briefly and continues only to jam again.
I can't imagine the CAN controller being in Data Overrun because I send a message every 0.5 seconds.
Is there anyone who can set me up or point me in the right direction please?
Thanks in advance,
John85
my program :
#include "LPC23xx.h" /* LPC23xx definitions */ #include "type.h" #include "irq.h" #include "can.h" #include "portlcd.h" #include <stdio.h>
CAN_MSG MsgBuf_TX1, MsgBuf_TX2; // TX and RX Buffers for CAN message CAN_MSG MsgBuf_RX1, MsgBuf_RX2; // TX and RX Buffers for CAN message extern void serial_init (void); /* external function: init serial UART*/ volatile DWORD CAN1RxDone, CAN2RxDone;
int main( void ) {
char str0[16]; /*Baud rate*/ char str1[16]; /*Can bericht */ char str2[16]; /* Please note, this PCLK is set in the target.h file. Since the example program is set to test USB device, there is only a limited number of options to set CCLK and PCLK when USB is used. The default setting is CCLK 48MHz, PCLK is 1/2 CCLK 24MHz. The bit timing is based on the setting of the PCLK, if different PCLK is used, please read can.h carefully and set your CAN bit timing accordingly. */ CAN_Init( BITRATE500K24MHZ ); /*-----------------------------------------------------------------------------------*/ switch(CAN1BTR) { case BITRATE1000K24MHZ: sprintf(str0, "%s", "1MBaud @ 24Mhz"); break;
case BITRATE100K24MHZ: sprintf(str0, "%s", "100KBaud @ 24Mhz"); break;
case BITRATE125K24MHZ: sprintf(str0, "%s", "125KBaud @ 24Mhz"); break;
case BITRATE250K24MHZ: sprintf(str0, "%s", "250KBaud @ 24Mhz"); break;
case BITRATE500K24MHZ: sprintf(str0, "%s", "500KBaud @ 24Mhz"); break;
default: sprintf(str0, "%s", "BR not defined"); break; } /* LCD Module.2x16 init */ LCD_init(); LCD_cur_off(); /* Update LCD Module display text. */
{ LCD_cls(); LCD_puts("CAN Receiver " "********* " ); delay (10000000); LCD_gotoxy (1,1); LCD_puts("CAN-BUS Speed= "); delay (10000000); LCD_gotoxy (1,2); LCD_puts ( str0 ); LCD_cls();
CAN_SetACCF( ACCF_BYPASS );
while (1) {
sprintf(str1,"%d--%d",MsgBuf_RX2.DataA, MsgBuf_RX2.DataB); /*data message*/ sprintf(str2,"CAN ID: %d",MsgBuf_RX2.MsgID); LCD_cls(); LCD_gotoxy(1,1); LCD_puts ( str2 ); LCD_gotoxy (1,2); LCD_puts ( str1 );
} }
return ( 0 ); }