Page 1 of 1

9_SER-TO-CAN Example not working

Posted: Mon 8. Jun 2020, 20:56
by mwbevington
Hi,

I'm working on a project that requires me to convert serial data to a J1939 frame. I thought I would use the example 9_SER-TO-CAN as a basis for my code. I find that the original (unmodified) code for this example will not run (file = ser_to_can.bin dated 3/18/2016). I note that in main.c the LED should be toggling between Green and OFF at a 1 Hz rate. It just stays RED all the time after this file is downloaded to the module.

I have validated that the hardware is okay using the example the module came preloaded with (6_CAN_TO_SER_BY_COMMAND). Can someone take a look at this code and help me figure out why it's not running?

Thanks,

Mark Bevington

Re: 9_SER-TO-CAN Example not working

Posted: Tue 9. Jun 2020, 08:53
by PEAK-Support
Could you compile, link and convert (hex2bin) the project ? The samples are only available as source code. Check the result of the make process!
I have compiled, linked and converted the sample code without any problems. Attached the bin file from the original sample code "9_SER-TO-CAN" of teh PCAN-RS232
ser_to_can.zip
BIN File - ready for flashing !
(5.53 KiB) Downloaded 3962 times

Re: 9_SER-TO-CAN Example not working

Posted: Tue 9. Jun 2020, 21:34
by mwbevington
Hi Uwe,

Thanks for the quick reply. The BIN file you sent loads and appears to work, as the LED toggles. I haven't had any issues compiling this...no errors. I did a diff and found where I had changed the CAN data rate from 500K to 250K in ser_to_can.h. I had forgot I had made this change to the original example code. This appears to be the issue, as if I set it back to 500K the code compiles and runs (LED flashes). I'm not sure why. I have zipped up my code. I directed the output from make to a file named makeoutput.txt

Would appreciate any suggestions you can provide as to what the issue might be, as the CAN bus I need to connect to runs at 250K (J1939)

Thank you,

Mark

Re: 9_SER-TO-CAN Example not working

Posted: Wed 10. Jun 2020, 11:26
by PEAK-Support
Youhave changed the bitrate to 250K in the ser_to_can.h file - that is OK how you did it

Code: Select all

#define canbitrate   CAN_BAUD_250K
Maybe the Bitrate Timimng will not fit to your targed? Have you connected the Device to the CAN-USB that you use for flashing and run PCAN-View with 250K to test it?
What happend when you send a CAN Frame from PCAN-View - what does the status line show?

Re: 9_SER-TO-CAN Example not working

Posted: Wed 10. Jun 2020, 18:22
by mwbevington
Hi Uwe,

I don't think it is a bit rate timing issue. My only target right now is a PCAN-USB Pro (FD). If I build the code to run at 500 Kbps everything works. The LED toggles on the PCAN-RS232, and serial data (at 9600 BPS) is correctly output as can frames with an ID=0x123. See Trace1.trc, as well as the screenshot PeakExplorerSetup_500Kbps.jpg. If I change the code to run at 250K (the only change), the PCAN-RS232 appears hung, as the LED stays constantly RED. There is no output seen by using Peak Explorer along with the PCAN-USB Pro. See PeakExplorerSetup_250Kbps.jpg.

My guess is that something is wrong with the initialization code for the LPC's CAN, when one sets it to run at 250K. To me, one of the "telling" details is that the LED always stays RED, which to me says that the code is stuck somewhere and not executing the toggling routine that is part of the while loop in main.c. I do not currently have a debugger for the LPC so can not easily figure out where things are "stuck".

FWIW, my system consists of a serial device transmitting ASCII data at 9600, 8N1, connected directly the the PCAN-RS232. The CAN port of the PCAN-RS232 is connected to the PCASN-USB Pro, along with appropriate termination resistors.

I'm open to any other suggestions.

Thanks,

Mark

Re: 9_SER-TO-CAN Example not working

Posted: Thu 11. Jun 2020, 09:23
by M.Gerber
Hello Mark,

We have a holiday here in Germany, thus please be patient until the next answer to your problem (anticipated tomorrow, Friday).

Thanks,
(also) Mark

Re: 9_SER-TO-CAN Example not working

Posted: Thu 11. Jun 2020, 19:16
by mwbevington
Hi Mark/Uwe,

I found it. In can_user.c there is a statement inside the CAN_UserInit() function that is used to initialize the CAN interface as follows:

// init CAN1
CAN_InitChannel ( CAN_BUS1, CAN_BAUD_500K);

I added ser_to_can.h to can_user.c as an include, and changed the previous statement to utilize the user defined CAN baud rate, as follows:

// init CAN1
CAN_InitChannel ( CAN_BUS1, canbitrate); //mwb, was hardcoded at CAN_BAUD_500K

I've got CAN data being output at 250K now, and LED is toggling as expected.

I have attached the updated can_user.c file so you can update the 9_SER-TO_CAN example

Thank you,

Mark

Re: 9_SER-TO-CAN Example not working

Posted: Mon 15. Jun 2020, 09:58
by PEAK-Support
We will change the sample so that the customer could easy change Birate only with one line of code - Thanks!