2022-02-16 07:44 PM
Hello there,
I am working with CAN on STM32F103. I want my MCU to send a message right when it receives a message so I put HAL_CAN_AddTxMessage function in HAL_CAN_RxFifo0MsgPendingCallback. I tried it with STM32F4 like this and it worked fine.
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
/* Do some other stuff here
* ...
*/
HAL_CAN_AddTxMessage(&hcan1, &TxHeader0, CAN1Tx0, &TxMailbox[0]);
HAL_CAN_AddTxMessage(&hcan1, &TxHeader1, CAN1Tx1, &TxMailbox[1]);
}
But I could not do so with STM32F1
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
/* Do some stuff here
* ...
*/
HAL_CAN_AddTxMessage(&hcan, &TxHeader, CANTx, &TxMailbox);
}
the compiler gave me warning
passing argument 1 of 'HAL_CAN_AddTxMessage' from incompatible pointer type [-Wincompatible-pointer-types] main.c
expected 'CAN_HandleTypeDef *' {aka 'struct __CAN_HandleTypeDef *'} but argument is of type 'CAN_HandleTypeDef **' {aka 'struct __CAN_HandleTypeDef **'}
Upload the code to the MCU and it could not send the message.
I also tried to put HAL_CAN_AddTxMessage in HAL_CAN_IRQHandler or USB_LP_CAN1_RX0_IRQHandler but it gave the same result. Any way to solve this? Many thanks!
Solved! Go to Solution.
2022-02-16 08:13 PM
hcan enters as a pointer you don't need the &
2022-02-16 08:13 PM
hcan enters as a pointer you don't need the &
2023-08-22 05:53 AM
Thanks so much, but in other project with NUCLEO-L432KC with the same code, I must be to write '&', ...why!?Thanks in advance for clarify this question !!
2023-08-22 06:38 PM
Because in the STM32F4 you're calling HAL_CAN_AddTxMessage and passing hcan1 which needs a pointer.
Then hcan in the STM32F1 interrupt is passed as a pointer so it doesn't need the '&' when you're calling HAL_CAN_AddTxMessage
If you changed hcan to &hcan1 then it'll work just like the STM32F4