2023-09-23 08:03 PM
I have stm32 bluepilll on which I am able to transmit CAN messages but CAN Receive interrupt is not generating.
I found while configuring that CAN RX pin(GPIO mode) is getting configured as Input mode. How accurate is this?
I think it should be Alternate function. I made PB8 as Alternate function still CAN Rx interrupt is not working.
Above statements are under stm32f1xx_hal_msp.c
I am using CAN RX1 interrupt, following are my configurations
static void MX_CAN_Init(void)
{
/* USER CODE BEGIN CAN_Init 0 */
/* USER CODE END CAN_Init 0 */
/* USER CODE BEGIN CAN_Init 1 */
/* USER CODE END CAN_Init 1 */
hcan.Instance = CAN1;
hcan.Init.Prescaler = 9;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_3TQ;
hcan.Init.TimeSeg2 = CAN_BS2_4TQ;
hcan.Init.TimeTriggeredMode = DISABLE;
hcan.Init.AutoBusOff = ENABLE;
hcan.Init.AutoWakeUp = DISABLE;
hcan.Init.AutoRetransmission = ENABLE;
hcan.Init.ReceiveFifoLocked = DISABLE;
hcan.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN_Init 2 */
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 18; // which filter bank to use from the assigned ones PA11
canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO1;
canfilterconfig.FilterIdHigh = 0x00000103<<5;
canfilterconfig.FilterIdLow = 0;
canfilterconfig.FilterMaskIdHigh = 0x00000103<<5;
canfilterconfig.FilterMaskIdLow = 0x0000;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 20; // how many filters to assign to the CAN1 (master can)
HAL_CAN_ConfigFilter(&hcan, &canfilterconfig);
if (HAL_CAN_Start(&hcan)!= HAL_OK)
{
Error_Handler();
}
HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO1_MSG_PENDING);
/* USER CODE END CAN_Init 2 */
}
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO1, &RxHeader, RxData);
if (RxHeader.StdId == 0x0000103)
{
rx=1;
}
}
2023-09-23 09:22 PM
Can Tx alone cannot work if Can Tx is working it means Can Rx is working or both Can Tx and Rx are not working. How do you know that Can Tx is working?
2023-09-23 09:33 PM
I have an USB to CAN analyser, I am sending a CAN message under while loop which I am able to see on my PC.
From the same analyser I am sending a CAN frame whose ID is being checked under callback function.
2023-09-23 09:36 PM
Try to transmit message from MCU and see if you are receiving messages may be at 1sec or 100msec on the tool.
2023-09-23 09:39 PM
This messages are transferred from MCU.I am able to see them on PC.
2023-09-23 10:25 PM
Which is your receive interrupt function, where are you putting the break point. I think you are not using the correct RxInterrupt function.
2023-09-23 10:32 PM
2023-09-23 10:37 PM
stm32f103c8t6 doesn't support CANFD, it supports standard and extended CAN and it has HAL_CAN_RxFifo1MsgPendingCallback.I am using CAN RX1 interrupt.
2023-09-24 02:06 AM
Transmit different message IDs try to disable filter and check.
2023-09-24 04:47 AM
I tried its not helping.