2022-02-08 08:35 AM
I have a STM32H745 Nucleo and I am trying to get the CAN peripheral working. I believe I have everything set up correctly (bit rate, RAM etc) but when I call HAL_FDCAN_AddMessageToTxFifoQ() the first time the peripheral goes back to INIT. The next call to it fails because the FIFO (size of 1 in current code) is full and the message never gets sent. I've attached the entire project including the ioc. The FDCAN configuration and sending code was basically copied from the the H7 DISCO board example. I've tried increasing the TxFifo size but nothing really changes. The FIFO fills up and then the AddMessage call fails. Always on the first call, the CCCR.INIT bit goes high when the line
hfdcan->Instance->TXBAR = ((uint32_t)1 << PutIndex);
is executed in the HAL_FDCAN_AddMessageToTxFifoQ() call.
Any help is appreciated.
Solved! Go to Solution.
2022-02-09 02:02 AM
Another point regarding the bitrate you're using.
I double checked your configuration:
FDCAN1 bitrate = 32MHz/ 2*(1+13+3) = 941kb/s which is not a common bitrate. I think you need 1MB/s, right?
2022-02-08 09:04 AM
Dear @ttatakis ,
I see you are using NUCLEO board.
So the questions are:
1- Did you add a transceiver for CAN communication as you are using normal mode (hfdcan1.Init.Mode = FDCAN_MODE_NORMAL)?
2- Did you connect a second node on CAN bus to acknowledge the sent messages?
If the above are not met, your example will never work.
CAN/CAN-FD are not UART or SPI, in normal mode you need to use transceiver +another CAN node on the bus to acknowledge/receive your messages.
You can use CAN in loopback mode in Nucleo configuration. Refer to the example provided in CubeH7 under Projects\STM32H743I-EVAL\Examples\FDCAN\FDCAN_Loopback
SofLit
2022-02-08 10:32 AM
The answer to both questions is yes- I have one of these (actually I've tried two already) https://www.ti.com/lit/ug/sllu231/sllu231.pdf. I think I've tried every jumper combination but if you have an explicit recommendation , I will try again.
And I have a CAN-USB adapter from Peak Systems for the other end with PCAN-Explorer running.
2022-02-08 01:20 PM
Woops- wrong data sheet: I have these (or the closest facsimile I can find): https://www.ti.com/lit/ug/sllu234a/sllu234a.pdf?ts=1634981608405
2022-02-09 01:11 AM
OK.. Clear.
- For JMP2, be sure you are using pin2 (Tx) and pin5 (Rx)
- Now check the jumper JMP1: STB should be tied to the ground. (if STB = VCC, the transceiver goes to standby mode).
- Fit one of the jumpers JMP4 or JMP5 to connect the termination resistor to the CAN bus. I suppose your CAN-USB adapter has one on its side.
- Don't fit JMP6 for the moment... and test
2022-02-09 02:02 AM
Another point regarding the bitrate you're using.
I double checked your configuration:
FDCAN1 bitrate = 32MHz/ 2*(1+13+3) = 941kb/s which is not a common bitrate. I think you need 1MB/s, right?
2022-02-09 06:17 AM
Yep- those were my 'preferred' jumper settings and left it that way last night. This morning I turned everything on and it worked! I must have gotten the USB-CAN adapter confused somehow and never re-started the app that talks to it to reset it (although I did unplug it a few times). Thanks for your bit rate check. I changed Seg1 to 12 and the adapter is receiving the 1Mb/sec messages with no errors. I assume the '1' in your formula is the Tsyncseg which is always 1 Tq (based on the reference manual Bit Timing section 59.4.4).
Thanks again for your help- forcing me to check things again.... and again!
2022-02-09 06:44 AM
Perfect!
Yes, 1 in the formula is for tSyncSeg..
Please mark the nearest answer related to your issue as answered by selecting "Select as best". This will help other users find that answer faster.
Thank you.