# CAN Bus Support

**URL:** https://community.simplefoc.com/t/can-bus-support/407
**Category:** hardware support
**Created:** [January 2, 2021, 9:25am UTC](https://community.simplefoc.com/t/can-bus-support/407 "2021-01-02T09:25:54Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![erwin74](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/e/5f9b8f/32.png) [@erwin74](https://community.simplefoc.com/u/erwin74)
#### Post date: [February 13, 2021, 1:20pm UTC](https://community.simplefoc.com/t/can-bus-support/407/22 "2021-02-13T13:20:17Z")

</div>

I couldn’t get it up and running on my discovery board, because of limited time. But what i saw so far are two points:

- you have enabled the interrupt for `HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);`, but you havn’t implemented an interrupt handler for it.  
like:  
`void CAN1_RX0_IRQHandler(void) { HAL_CAN_IRQHandler(&SimpleCan::hcan); }`  
…look into the can examples comming from stm (file ‘stm32f4xx\_it.c’) or from generated CubeMX code. For the STM324xG-EVAL board they offer some CAN samples with interrupts.

- second thing is that you have to make hcan static (`static CAN_HandleTypeDef hcan;`) otherwise you can not access it from the interrupt handler (don’t forget the static initializer `CAN_HandleTypeDef SimpleCan::hcan = { };`).

Hope this brings you on the right track. Have fun!

---

<div class="post-metadata">

### Author: ![Owen\_Williams](https://community.simplefoc.com/user_avatar/community.simplefoc.com/owen_williams/32/105_2.png) [@Owen\_Williams](https://community.simplefoc.com/u/Owen_Williams)
#### Post date: [March 2, 2021, 9:54pm UTC](https://community.simplefoc.com/t/can-bus-support/407/23 "2021-03-02T21:54:36Z")

</div>

@JorgeMaker - I have interrupts working for HAL\_CAN (stm32f405 vesc board). I’ve also sorted out CAN speeds which unlike FDCAN you have to work out prescalers and time segments for. Pain ☹ Unfortunately the speeds are going to be dependent on your PCKL1 freq (42MHz for me) - so might need replacing.

> **[GitHub - owennewo/SimpleCAN: A CAN Bus library for Arduino and other platforms](https://github.com/owennewo/SimpleCAN)**
>
> A CAN Bus library for Arduino and other platforms

The interface is a little different to @erwin74. Perhaps we can work towards a common abstraction?? I’ve looked at esp32 as a 3rd CAN abstraction but it’s newer API assumes you are using tasks/threads I think. Challenging!

If we had an abstraction then we could write a SimpleFOC CanCommander which uses this abstraction and is aware of SimpleFOC config and actions. This would allow can bus message such as “set Node 4’s velocity P term to 4” or “what is the velocity of Node 3”. The commander would receive these messages and know what todo with BLDCMotor to set or obtain the info.

---

<div class="post-metadata">

### Author: ![JorgeMaker](https://community.simplefoc.com/user_avatar/community.simplefoc.com/jorgemaker/32/546_2.png) [@JorgeMaker](https://community.simplefoc.com/u/JorgeMaker)
#### Post date: [March 2, 2021, 10:21pm UTC](https://community.simplefoc.com/t/can-bus-support/407/24 "2021-03-02T22:21:40Z")

</div>

Hi @Owen_Williams,

Greate news 🙂

I will test your implementation as soon as I receive a new STM32F405RGT6, it’s on its way from China 🙂 Unfortunately, I destroyed my MCU due to an ESD event caused by allowing more current than my power supply could handle.

I really like the interface you have implemented, it is not that different from the one @erwin74 implemented. It would be great to develop a top layer that uses this interface and is able to act on SimpleFOC. If I have time this weekend and I will try to make a proposal.

---

<div class="post-metadata">

### Author: ![ultra.robotics](https://community.simplefoc.com/user_avatar/community.simplefoc.com/ultra.robotics/32/721_2.png) [@ultra.robotics](https://community.simplefoc.com/u/ultra.robotics)
#### Post date: [March 8, 2021, 9:49pm UTC](https://community.simplefoc.com/t/can-bus-support/407/25 "2021-03-08T21:49:53Z")

</div>

Hi Can-Experts of the SimpleFOC community!

Thanks to the code of @Owen_Williams and @erwin74, I got bi-directional CAN working. For my setup I am using an Arduino Uno with a MCP2515 and the B-G431B-ESC1.

Everything works perfect with the standard code from [Github](https://github.com/owennewo/youtube_can). But when I want to combine my previous SimpleFOC code, I get many problems:

- Only thing I add: Serial.print(“test”); in the loop and the codes stops working.
- Or once I add the SimpleFOC library, it already stops working after BLDCMotor motor = BLDCMotor(11);
- Or if I send more than two bytes to the standard code, it will also stops working.

I know that these are quite specific questions! So I am not looking for a precise answer. I want to ask advice how to solve these kind of things! Especially the first (Serial) and second point (Adding SimpleFOC code). Normally I can solve some problems but when adding one simple line of code and the whole board stops working (I always check with a led because Serial can sometimes be inconsistent with this board!), than I am quite lost!

Does someone have tips to help me further? 🙂

Greetings,

Wittecactus

---

<div class="post-metadata">

### Author: ![Owen\_Williams](https://community.simplefoc.com/user_avatar/community.simplefoc.com/owen_williams/32/105_2.png) [@Owen\_Williams](https://community.simplefoc.com/u/Owen_Williams)
#### Post date: [March 15, 2021, 8:20pm UTC](https://community.simplefoc.com/t/can-bus-support/407/26 "2021-03-15T20:20:25Z")

</div>

@ultra.robotics - did you get past your CAN/Serial issues? I think on another thread you may have got more stability by using Arduino IDE. Does this mean you’re happy with your CAN situation?

---

<div class="post-metadata">

### Author: ![ultra.robotics](https://community.simplefoc.com/user_avatar/community.simplefoc.com/ultra.robotics/32/721_2.png) [@ultra.robotics](https://community.simplefoc.com/u/ultra.robotics)
#### Post date: [March 16, 2021, 9:51am UTC](https://community.simplefoc.com/t/can-bus-support/407/27 "2021-03-16T09:51:02Z")

</div>

Hi @Owen_Williams,

Thanks for your reply, I really appreciate that!

I forgot to update this reply! Arduino IDE did the trick for me. SimpleFOC code is already implemented and I am hoping to get the first leg movements in the coming week 🙂.

The only thing I could not fix is that I can not send more than two bytes. When I send more than two bytes, the whole board crashes. For now it is fine because I convert a float into an integer and the bytes of this integer are than send via the CAN. But I am still curious why this is the case!

I think that it could maybe be related to the bit of the `Data length code` function.

---

<div class="post-metadata">

### Author: ![Owen\_Williams](https://community.simplefoc.com/user_avatar/community.simplefoc.com/owen_williams/32/105_2.png) [@Owen\_Williams](https://community.simplefoc.com/u/Owen_Williams)
#### Post date: [March 16, 2021, 7:15pm UTC](https://community.simplefoc.com/t/can-bus-support/407/28 "2021-03-16T19:15:17Z")

</div>

Looking forward to you ‘showing a bit of leg’. 🙂

I know some stm32 peripherals can’t be used at the same time. Does the Serial work in a simple sketch but stop working when you do CAN?

---

<div class="post-metadata">

### Author: ![ultra.robotics](https://community.simplefoc.com/user_avatar/community.simplefoc.com/ultra.robotics/32/721_2.png) [@ultra.robotics](https://community.simplefoc.com/u/ultra.robotics)
#### Post date: [March 17, 2021, 8:38am UTC](https://community.simplefoc.com/t/can-bus-support/407/29 "2021-03-17T08:38:17Z")

</div>

Since switching back to arduino IDE. Serial does work in a simple sketch but does also work combined with CAN code! 🙂

---

<div class="post-metadata">

### Author: ![JorgeMaker](https://community.simplefoc.com/user_avatar/community.simplefoc.com/jorgemaker/32/546_2.png) [@JorgeMaker](https://community.simplefoc.com/u/JorgeMaker)
#### Post date: [March 17, 2021, 1:44pm UTC](https://community.simplefoc.com/t/can-bus-support/407/30 "2021-03-17T13:44:52Z")

</div>

Analyze the content of the _platformio.ini_ file …, most likely the differences come from there.

---

<div class="post-metadata">

### Author: ![Scarittagle](https://community.simplefoc.com/user_avatar/community.simplefoc.com/scarittagle/32/9666_2.png) [@Scarittagle](https://community.simplefoc.com/u/Scarittagle)
#### Post date: [February 18, 2026, 9:46am UTC](https://community.simplefoc.com/t/can-bus-support/407/31 "2026-02-18T09:46:17Z")

</div>

I know it’s a old thread but @Owen_Williams @JorgeMaker looks like it would be great to add support for DroneCAN (**[libcanard](https://github.com/OpenCyphal/libcanard)**) in the SimpleCANio as well! it’s a widely used protocol in UAS industry, thanks for the code base you have it here

[Previous page](https://community.simplefoc.com/t/can-bus-support/407.md?page=1)
