9_SER-TO-CAN Example not working

Programmable Converter for RS-232 to CAN
Post Reply
mwbevington
Posts: 9
Joined: Thu 28. Jul 2011, 19:02

9_SER-TO-CAN Example not working

Post by mwbevington » Mon 8. Jun 2020, 20:56

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
Mark W. Bevington
Maven Engineering
Yerington, NV, USA
e) mwbevington@ieee.org
c) 775.315.3088

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1130
Joined: Fri 10. Sep 2010, 19:34

Re: 9_SER-TO-CAN Example not working

Post by U.Wilhelm » Tue 9. Jun 2020, 08:53

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 11 times
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

mwbevington
Posts: 9
Joined: Thu 28. Jul 2011, 19:02

Re: 9_SER-TO-CAN Example not working

Post by mwbevington » Tue 9. Jun 2020, 21:34

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
Attachments
9_SER-TO-CAN.zip
(161.81 KiB) Downloaded 12 times
Mark W. Bevington
Maven Engineering
Yerington, NV, USA
e) mwbevington@ieee.org
c) 775.315.3088

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1130
Joined: Fri 10. Sep 2010, 19:34

Re: 9_SER-TO-CAN Example not working

Post by U.Wilhelm » Wed 10. Jun 2020, 11:26

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?
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

mwbevington
Posts: 9
Joined: Thu 28. Jul 2011, 19:02

Re: 9_SER-TO-CAN Example not working

Post by mwbevington » Wed 10. Jun 2020, 18:22

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
Attachments
ser_to_can.h
(1.4 KiB) Downloaded 9 times
Trace1 at 500Kbps.trc
(10.04 KiB) Downloaded 9 times
PeakExplorerSetup_500Kbps.JPG
PeakExplorerSetup_500Kbps.JPG (62.08 KiB) Viewed 242 times
PeakExplorerSetup_250Kbps.JPG
PeakExplorerSetup_250Kbps.JPG (54.66 KiB) Viewed 242 times
Mark W. Bevington
Maven Engineering
Yerington, NV, USA
e) mwbevington@ieee.org
c) 775.315.3088

User avatar
M.Gerber
Design & Documentation
Design & Documentation
Posts: 65
Joined: Mon 13. Sep 2010, 16:34

Re: 9_SER-TO-CAN Example not working

Post by M.Gerber » Thu 11. Jun 2020, 09:23

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

mwbevington
Posts: 9
Joined: Thu 28. Jul 2011, 19:02

Re: 9_SER-TO-CAN Example not working

Post by mwbevington » Thu 11. Jun 2020, 19:16

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
Attachments
can_user.c
(2.93 KiB) Downloaded 11 times
Mark W. Bevington
Maven Engineering
Yerington, NV, USA
e) mwbevington@ieee.org
c) 775.315.3088

User avatar
U.Wilhelm
Sales & Support
Sales & Support
Posts: 1130
Joined: Fri 10. Sep 2010, 19:34

Re: 9_SER-TO-CAN Example not working

Post by U.Wilhelm » Mon 15. Jun 2020, 09:58

We will change the sample so that the customer could easy change Birate only with one line of code - Thanks!
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------

Post Reply