Skip to main content
Visitor II
March 15, 2019
Solved

How do I implement a CAN Bus on my STM32F042k6 without using Std Lib or Cube MX?

  • March 15, 2019
  • 1 reply
  • 3014 views

I am trying since a couple of days to implement a CAN Bus communication for my above mentioned board without success. I wish to do this using the Registers only. Can someone give some hints on how I should proceed? or a link?. Thanks in advance.

    This topic has been closed for replies.
    Best answer by mcdino.5338840562911753E12

    I have had the solution to my problem. The issue was in the Bit Timing Register. The values were not corresponding to my CAN Adapter

    1 reply

    Visitor II
    March 15, 2019

    I would get the SPL for the F0xx, and take a CAN example as starting point.

    https://www.st.com/content/st_com/en/products/embedded-software/mcu-mpu-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32048.html

    Take the relevant register settings and initialization sequence, and re-code it your way.

    No need to make things too difficult.

    > I wish to do this using the Registers only.

    I would still go with the CMSIS header files and naming conventions.

    This is zero extra effort, and makes your code more readable & portable.

    Visitor II
    March 16, 2019

    I followed the CAN example in the SPL and now I have a problem. The CAN Intterupt doesnot fire. Can someone give me some help?

    Graduate II
    March 16, 2019

    >>Can someone give me some help?

    You make it very hard to help you. That something "doesn't work" imparts very little information, there are a million ways to fail. So rather that take the Thomas Edison approach, define clearly what you're doing so other can inspect. Determine what pieces actually work as expected so you can focus on the parts/point where failure occurs. If you want to do register level programming the onus is on you to assimilate the Reference Manual. Perhaps use the SPL/HAL to prove if your hardware is viable, and then recode at a register level that suits you.

    Do you have the vectors set up? Do you enable the interrupt in the NVIC? Do you enable the interrupt in the peripheral? Do you actually get any events causing interrupts?