STM32F042G6U CAN - Can't receive frames
Hello,
I have an issue with the CAN bus on STM32F042G6 µC.
For the moment I just want to receive Frames from an other controller (STM32G0B1) and it doesn't work at all.
I am using PA11 as Rx Pin and PA12 as Tx Pin Pins.
Here is the configuration part with a 12MHz external clock :
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 = CAN;
hcan.Init.Prescaler = 16;
hcan.Init.Mode = CAN_MODE_NORMAL;
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan.Init.TimeSeg1 = CAN_BS1_1TQ;
hcan.Init.TimeSeg2 = CAN_BS2_1TQ;
hcan.Init.TimeTriggeredMode = DISABLE;
hcan.Init.AutoBusOff = DISABLE;
hcan.Init.AutoWakeUp = DISABLE;
hcan.Init.AutoRetransmission = DISABLE;
hcan.Init.ReceiveFifoLocked = DISABLE;
hcan.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN_Init 2 */
/* USER CODE END CAN_Init 2 */
}I tried to read the frame sent with this code :
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_CAN_Init();
if(HAL_CAN_Start(&hcan) != HAL_OK)
Error_Handler();
if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
Error_Handler();
}
while (1)
{
HAL_Delay(500);
}
}I don't understand why but it is impossible for me to go in the HAL_CAN_RxFifo0MsgPendingCallback function when a message is received. I checkes the RX Pin with an oscilloscope and the CAN frame is correct on this Pin.
I already found this topic https://community.st.com/t5/stm32-mcus-products/stm32f042g6ux-can-issue/td-p/675078 and follow what was said but nothing works. I don't have any filters, I enabled interrupts for CAN on NVIC menu and in CAN menu. My Rx pin is set to Pull-Up and both my µC have the same exact configuration.
I send a the configuration of my CAN, NVIC and GPIO in .ioc file on attached image.
Do you have any idea why it doesn't work ?
Thank you in advance for your reply,
Yann Di Padova
