2
\$\begingroup\$

I would like to build a project based on STM32 that interfaces with a CAN network. The CAN network has a 250 kbit/s baud rate.

On this network I have to:

  • Log messages from 127 nodes with IDs between 0x381 and 0x3FF (each node transmits one message per second).
  • Transmit messages to nodes with ID between 0x581 and 0x5FF.
  • Receive responses to these messages that will have IDs between 0x601 and 0x67F.

I was thinking of using an STM32 with two CAN channels. My intention is to set up two different filters on IDs and limit interruptions. Is that a good choice? Can it be done with only one CAN?

I have doubts about the kind and the speed of processor to use. Can an STM32F1 be sufficient? Or do I need an F4?

\$\endgroup\$

closed as off-topic by Marcus Müller, Leon Heller, Enric Blanco, Voltage Spike, PeterJ Jun 21 '17 at 10:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ "Can an STM32F1 be sufficient? Or do I need an F4?" - If you only need to read data at 250kbps max and forward it to some storage or other device, the F1 will have ample performance. But no way for us to tell if you don't disclose what else the MCU must do concurrently. \$\endgroup\$ – JimmyB Jun 20 '17 at 8:17
  • \$\begingroup\$ You can configure multiple filters for CAN messages. If they're not sufficient you still have the option of filtering in software. \$\endgroup\$ – JimmyB Jun 20 '17 at 8:21
  • \$\begingroup\$ I had forgotten multiple filters. I'm going to re read the datasheet :). \$\endgroup\$ – Katte Jun 20 '17 at 9:21
  • 1
    \$\begingroup\$ What specific feature in a CAN Logger are you looking for that existing CAN loggers (with analysis software) do not offer? \$\endgroup\$ – Jeroen3 Jun 20 '17 at 9:32
  • \$\begingroup\$ I have simplified the question, but it is not just a CAN network analyzer. I have to collect data and perform some simple actions. \$\endgroup\$ – Katte Jun 20 '17 at 14:14
15
\$\begingroup\$

The shortest CAN frame is 55 bit times, so in the very worst case situation with a completely saturated bus consisting of one data byte frames (which is not really realistic for a CAN bus with any sort of useful performance) you will be receiving a frame every 220 µS (55 / 250000). The cheapest ST microcontroller that has a CAN controller is the STM32F042 ($1), and this has a maximum CPU frequency of 48 MHz. So with this device, you would have approximately 10560 (48 * 220) instructions per message in the worst case.

In terms of dealing with the CAN controller and processing CAN messages, this is a considerable amount of processing power - enough to dump the messages into an EEPROM or SD card with a lot of post processing done on them if required. If that is really all your device is doing then I wouldn't worry about it too much and any of the STM32 devices will be fine. If anything, RAM is probably going to be more of an issue if you need to buffer messages, etc.

In practice I doubt the bus is running anywhere near full capacity (though only you know this) and if you can use the hardware filters to ignore a portion of the messages, then you just gain more and more instruction cycles per message.

\$\endgroup\$
  • 2
    \$\begingroup\$ You assume that each instruction takes exactly one cycle. This is not true for any instruction which touches memory (see the technical reference manual on the Cortex-M3 for example, holds for M0 too) or arithmetics such as multiply and divide. So I’d be conservative and divide that number by two or four, at least. \$\endgroup\$ – Jonas Schäfer Jun 20 '17 at 15:46

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