2021-09-08 06:28 AM
I am trying to set up a hal can receive interrupt. After thorough googling, I found that HAL_CAN_Receive_IT is deprecated and that I should now be using HAL_CAN_ActivateNotification with a callback function. Unfortunately no one describes how to do this. In fact, if I search the HAL manual (um1785) for "HAL_CAN_ActivateNotification" I get 0 results. It looks like the STM32F0 line just doesnt have CAN interrupt capabilities.
Solved! Go to Solution.
2021-09-09 04:11 AM
Dear @Iviti.1
You can refer to the example provided under STM32CubeF0 downloadable from this link.
So unzip the file and go under either:
Projects\STM32072B_EVAL\Examples\CAN\CAN_Networking
or
Projects\STM32091C_EVAL\Examples\CAN\CAN_Networking
The example calls HAL_CAN_ActivateNotification() API and uses CAN Rx in interrupt context.
If you find this answers your question, please mark this topic as answered by selecting Select as best. This will help other users find that answer faster
SofLit
2021-09-09 04:11 AM
Dear @Iviti.1
You can refer to the example provided under STM32CubeF0 downloadable from this link.
So unzip the file and go under either:
Projects\STM32072B_EVAL\Examples\CAN\CAN_Networking
or
Projects\STM32091C_EVAL\Examples\CAN\CAN_Networking
The example calls HAL_CAN_ActivateNotification() API and uses CAN Rx in interrupt context.
If you find this answers your question, please mark this topic as answered by selecting Select as best. This will help other users find that answer faster
SofLit
2021-09-09 01:27 PM
I am not entirely sure how to run that example without an .ioc code. Inspecting it visually, I see that it sends out information using the
HAL_CAN_AddTxMessage(&CanHandle, &TxHeader, TxData, &TxMailbox)
command.
In my code, my system goes into there a few times then error's out. Nothing is being sent out. Almost like the message gets put into the transmit mailboxes but then nothing gets sent out.
2021-09-10 03:20 AM
Hello,
CubeMx is used only for HW configuration not to built an application. So HAL_CAN_AddTxMessage() is not part of CubeMx code generation but it's up to the user to add his own code related to his specific application and this should be between:
/* USER CODE BEGIN <XX> */
/* USER CODE END <XX> */
The example that I've pointed to, contains the sequence of code to use CAN in Rx in interrupt context and you can inspire from that example to adapt it to your usage.
Please refer to readme file located in example folder in order to have an idea how to use the example and on which HW condition this should be used then you can have idea how to adapt it to your needs..
SofLit
2021-09-10 05:17 AM
I understand that in order to do can rx, first you need to tell it that you will be expecting a message, then you need a callback to the can interrupt. What I was saying with the last message is that can Tx is not even working for me. Perhaps I should make that a new post.
2021-09-20 11:54 AM
turned out the stby pin on the can transceiver needed to be explicitly grounded. Now I am able to Tx on the stm32f0. Unfortunately Rx does not work. There is no option to turn on rx interrupt handler in nvic settings
2021-09-21 01:50 AM
This is the option to enable CAN interrupt in CubeMx for F0:
2021-09-21 07:58 AM
Running through the code in debug mode, I find that instead of interrupting to "HAL_CAN_RxFifo0MsPendingCallback" it seems to be interrupting to "CEC_CAN_IRQHandler". In fact, if I do "HAL_CAN_GetRxMessage" there, I can read the message.
2021-09-21 10:59 AM
unfortunately I cant get it to naturally reach the callback because of the line :
if ((interrupts & CAN_IT_RX_FIFO0_FULL) != 0U)
where it compares the fifo 0 full interrupt flag with the interrupt enable register. interrupts = 2, CAN_IT_RX_FIFO0_FULL = 4
2021-09-21 12:49 PM
I can set
hcan.Instance->IER = 4;
to get past that if statement, but then I am stuck at
if ((rf0rflags & CAN_RF0R_FULL0) != 0U)
where rf0rflags = 2 and can_rf0r_full0 = 8