2023-09-14 04:35 AM
Hey all,
I’ve recently encountered an issue with setting up the CAN module on my STM32F4 and hope that someone is able to help me:
After buying the SN65HVD230 CAN Board, I tried to set up the MCU so it can communicate with the CAN Bus. For that I soldered cables to IO 1 and 2 on my Dev Board and changed their setup in the STM32MX configurator. I was able to detect signals going in and out on the Tx and Rx line as well as on CANH and CANL. So there should be no problem with the wiring.
My problem is with the configuration of the CAN message itself. The message doesn’t seem to be able to be configured, meaning that any way I try, it doesn’t change the message that actually gets transmitted. For example the ID is always set to 0x7FE or the TxHeader.DLC parameter is always set to 3.
I was able to narrow the problem down to the CAN register. The necessary code meant to write into the registers doesn't seem to alter the data int the register at all. While in debug mode I went step by step through the lines and for example when coming to the following line in the HAL functions, no new values are written in the hcan[...].TIR register.
The register stays on what I assume is a default value. Again: even though there is a command in code (see picture) to write value x into register sMailBox[0].TIR, the value of the register stays at the default value of 0xFFDFFFF2.
In my research into the problem I read that it could stem from the timer not setup for the CAN and GPIO. However I made sure that everything is getting initialized, including the timers. I will still attach my code, maybe I made a mistake there. This is my first project with STM32 so there may just be a basic misunderstanding on my side how to set everything up.
I'd appreciate any help I can get!
Solved! Go to Solution.
2023-09-20 12:31 AM
UPDATE: I was able to get it working by enabling the CAN1. After looking further into the documentation I realized, that CAN2, which I was using because I used the GPIOs as the TX and RX line, was a Slave CAN. By enabling CAN1 and its clock, I got CAN2 to work.
2023-09-20 12:31 AM
UPDATE: I was able to get it working by enabling the CAN1. After looking further into the documentation I realized, that CAN2, which I was using because I used the GPIOs as the TX and RX line, was a Slave CAN. By enabling CAN1 and its clock, I got CAN2 to work.
2023-09-20 06:21 AM
Hello @SalomonD and welcome in the Community :),
Glad to know that the issue is fixed.
I confirm that, If you want to use CAN2, you have to enable CAN1 clock even if it will be not used.
Thank you for sharing the solution. It may help the community members who are having the same issue.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.