Skip to main content
Jim Seymour
Senior
June 18, 2018
Question

STM32F042 Is HAL_CAN_ConfigFilter() required?

  • June 18, 2018
  • 3 replies
  • 3247 views
Posted on June 18, 2018 at 23:06

I'm trying to get an interrupt-driven CAN receiver working on a STM32F042K6- but I'm not having much luck.

I'veconfigured the CAN module in CubeMX and the code it generates makes sense to me - and seems to match theinstructions listed inthe User Manual.

However,I've seen some posts here that imply that filtering is required. I want to receive ALL messages, so I didn't bother callingHAL_CAN_ConfigFilter(). But I've since addedthat call - but I'm still not receiving anything.

Can someone help me with a simple interrupt-driven receive example?

I'mattaching a subsetof my code. It uses a callback function to set a flag that my main loop inspects. Can anyone see what I might be doing wrong?

Thanks.

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.

    3 replies

    T J
    Senior III
    June 19, 2018
    Posted on June 19, 2018 at 03:21

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6v4&d=%2Fa%2F0X0000000bxz%2FbJJJkJzcZ1lRO9YFRUFMGpYJXwJV7MyP9JKCt0ix_Co&asPdf=false
    Ben K
    Senior III
    June 19, 2018
    Posted on June 19, 2018 at 18:33

    You always need to set up a filter if you want to receive CAN frames. It is not only necessary for filtering out messages, but it also decides to which FIFO the frames will be loaded into. To receive all frames, regardless of type or ID, you need to set up a masking filter where all mask fields are zero.

    Jim Seymour
    Senior
    June 19, 2018
    Posted on June 19, 2018 at 18:48

    Thank you.  It's a shame they don't mention this in the 'How to use this driver' section of the User Manual.

    I'll do some more experiments...  (My main problem is that I'm bringing up a new board - so I can't be sure whether what I'm seeing is a software or a hardware issue).

    Ben K
    Senior III
    June 19, 2018
    Posted on June 19, 2018 at 18:57

    I can recommend using the loopback mode of the CAN to test whether you have set the peripheral correctly. In loopback mode the transmission line is directly fed back on the receive line, so you can receive your own frames even without a bus or a PHY connected. (The peripheral also ACK-s its own frames.)

    Jim Seymour
    Senior
    June 21, 2018
    Posted on June 22, 2018 at 00:10

    Success!

    Short version: ST's CAN interrupt handler clears the CAN_IT_FMP0 flag when an error is detected.  In our system, we would often (always?) see at least one glitch on the line when we powered up our transceiver.  This cleared the FMP0 flag, so receives from that point forward were disabled.

    For the long story, see a new post that I will compose in a few minutes...