cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for simple CAN receive example for STM32F042

Jim Seymour
Senior
Posted on April 17, 2018 at 22:52

I am looking for a simple CAN Receive example for the STM32F042.  The example I usually see cited (STM32072B_EVAL\Examples\CAN\CAN_Networking) is really all about sending a message when a button is pressed.

I'm using STM32CubeMX v4.25.0 along with the STM32CubeF0 Firmware Package V1.9.0.

What I need is a better understanding of how I can perform a non-blocking receive operation in my main loop.

I don't think I need interrupts or DMA - but if they're required, I'm OK with that.

My project is to listen to the CAN bus and when a specific message comes in, respond with a different specific message.  This should be quite simple - but the documentation I've found so far is not clicking for me.

Thanks.

2 REPLIES 2
David Pekin
Senior
Posted on April 17, 2018 at 23:02

I just went though that.  In the CAN_rx callback function I copied the CAN data to my own buffer and then set a global CAN_Received flag to true.  I monitor the CAN_Received flag in the main loop and process my buffer with the CAN data at that time.  

Oh, dont' forget to re-enable CAN receive after yo process the buffer.

Good luck.

Posted on April 17, 2018 at 23:09

Thanks!  I'd missed the callback functions when I was looking through that example earlier.

This method should work well for me.  In fact, it looks like they check the message and re-enable receives directly in the callback function.

And if it doesn't work, I'll be back!  :)