1
\$\begingroup\$

I would like to build a tool for viewing CAN protocol data on my computer. The CAN protocol data is captured using a microcontroller (STM32F4 discovery board) and sent to a PC via a serial port. My requirement is to send only CAN ID, DLC, DATA and time stamp (i.e at what time a particular CAN ID was received).

I have a few questions that I couldn't find good results for after searching the Internet:

  1. Is it possible to send CAN data via the serial port using some compression techniques for the data packets since the CAN protocol operates at 1Mbps and I am planning to run the serial port at 115200 baud rate? If yes, could you provide information or links?

  2. Have you seen any similar projects which send 1Mbps CAN data via serial port. If yes, could you provide information or links?

\$\endgroup\$
2
  • \$\begingroup\$ Why serial port when the discovery board has USB? \$\endgroup\$
    – Turbo J
    May 18, 2013 at 13:39
  • 1
    \$\begingroup\$ Sending data via serial port is easy. Sending via USB needs additional code in microcontroller and also on the PC side \$\endgroup\$
    – robomon
    May 18, 2013 at 13:44

2 Answers 2

2
\$\begingroup\$

I suppose that your CAN devices won't be sending data all the time. Implement a buffer (e.g. a circular buffer) and fill it while you receive data, then send out the data via your serial port. Once the buffer overflows, make sure you signal that to the host as well.

Compression only makes sense when you know your data. If the data is random, you could use e.g. RLE, which is a quite simple type of encoding and doesn't require much calculation power.

But as I said before, I don't think you will need that.

\$\endgroup\$
2
  • \$\begingroup\$ If your buffer is overflowing quickly, Can you reduce CAN Baud Rate?? CAN can run at 125/250 kbps too... If your other nodes on bus allow you! \$\endgroup\$
    – Swanand
    May 20, 2013 at 6:54
  • \$\begingroup\$ i think DMA is faster than using software buffer for CAN recieving and serial transmitting \$\endgroup\$
    – ElectronS
    Jan 24, 2016 at 14:44
1
\$\begingroup\$

I would suggest increasing the serial baud to 1Mbps, just check if your clock divides evenly so that there is little error.

It will be hard to compress the Data since in some packets it won't be possible and in others will (0,0,0,0,0,0,0,0 as data for example).

If you cannot increase the Baud, then you could rely on a big buffer. The CAN won't be transmitting all the time, it will have idle times, so you could just store everything you receive in a FIFO and just have a function that keeps sending the FIFO until it's empty, if you receive new CAN data, just add it to the FIFO. It should catch up if the CAN is not that busy.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.