2024-04-09 11:45 PM - last edited on 2024-04-10 12:54 AM by SofLit
Hi amazing community.
I am working with stm32f429 and cube ide.
This is my configuration for the project
/**
* @brief CAN1 Initialization Function
* None
* @retval None
*/
static void MX_CAN1_Init(void)
{
/* USER CODE BEGIN CAN1_Init 0 */
/* USER CODE END CAN1_Init 0 */
/* USER CODE BEGIN CAN1_Init 1 */
/* USER CODE END CAN1_Init 1 */
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 18;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = ENABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = ENABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN1_Init 2 */
/* USER CODE END CAN1_Init 2 */
}
With the configuration above i am not able to enter inside the following callback funxtion sending messages wit canbus
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
CAN_RxHeaderTypeDef header;
uint8_t data[8];
uint32_t cmd_id;
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &header, data) == HAL_OK)
{
if ((can_dev.rx_queue_in+1)%CAN_RX_QUEUE != can_dev.rx_queue_out && header.IDE == CAN_ID_EXT)
{
// filtro messaggi destinati al nodo
cmd_id = header.ExtId;
if (cmd_id == can_dev.cfg_id || (can_dev.base != 0 &&
(
cmd_id == can_dev.base + can_dev.rec_offset*MSG_CFG_STATUS ||
cmd_id == can_dev.base + can_dev.rec_offset*MSG_OUT_ENABLE ||
cmd_id == can_dev.base + can_dev.rec_offset*MSG_INP_ENABLE ||
cmd_id == can_dev.base + can_dev.rec_offset*MSG_HW_VER ||
cmd_id == can_dev.base + can_dev.rec_offset*MSG_FW_VER ||
cmd_id == can_dev.base + can_dev.rec_offset*MSG_OUT_FREE
))) {
can_dev.rx++;
memcpy(&can_dev.rx_msg_queue[can_dev.rx_queue_in].header, &header, sizeof(CAN_RxHeaderTypeDef));
memcpy(can_dev.rx_msg_queue[can_dev.rx_queue_in].data, data, sizeof(data));
can_dev.rx_queue_in = (can_dev.rx_queue_in + 1) % CAN_RX_QUEUE;
}
}
can_dev.error_glb = 0;
can_dev.tot_rx++;
}
}
Can you please tell me if you see mistakes in the configuration or something else ?
Thanks a lot
Solved! Go to Solution.
2024-04-13 09:55 AM
You CANNOT ENTER THE CALLBACK if the CAN filter is not correctly configured. As I understood you didn't see the thread I provided to you on how to set FilterBank and SlaveStartFilterBank and the answer is there. You need more effort from your side to help you efficiently.
2024-04-13 10:20 AM
Double check NVIC settings, Vector Table entries, and linkage, the IRQHandler's themselves and that they call back into the HAL subsystem with the correct instance, that in turn calls your call back.