2016-02-25 07:30 AM
Hello,
I am trying the SCE Interrupt on the STM32F429ZI microprocessor. In a interrupt trasmission the controller detects a possible error and it sets the SCE interrupt. Instead, if I switch to a polling transmission (I only remove the TX interrupt settings from NVIC initializzation) I don't see anymore the SCE interrupt. I am using STM32Cube MX and HAL library v1.4.3. In my opinion it is a strange behaviour. What do you think? Thanks. Alex2016-03-17 06:29 AM
Good Afternoon,
does someone know where I could find an example of the CAN HAL library use in interrupt mode?? Thanks.2016-03-17 08:04 AM
Hi pavone.alessandro,
Interrupt mode is used for data reception in the example STM32Cube_FW_F4_V1.11.0\Projects\STM324x9I_EVAL\Examples\CAN\CAN_Networking that you may find in the STM32Cube Repository.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2016-03-17 09:06 AM
Thank you very much, Mayla.
I need also a Trasmission and SCE Interrupt examples for HAL library. Probably, I do some mistake because I have some strange behaviour that I don't understand. For example: 1) TX polling, RX interrupt, SCE interrupt --> If I start the execution of my program with an error on the bus (for example Reciving Warning REC=255) --> I see the SCE Interrupts during the program execution --> All OK; 2) TX polling, RX interrupt, SCE interrupt --> If I start the execution of my program without CAN BUS problem, I don't receive SCE Interrupt but I see that ESR register change its value (it signals the correct problem on the CAN line). Can someone help me? If you need some more information, ask it to me. My Init: /* CAN2 init function */ void MX_CAN2_Init(void) { BYTE ucCANNodeId = 1; CAN_FilterConfTypeDef sFilterConfig; DWORD ulCanNodeId = 0x01; hcan2.Instance = CAN2; hcan2.Init.Prescaler = 16; hcan2.Init.Mode = CAN_MODE_NORMAL; hcan2.Init.SJW = CAN_SJW_1TQ; hcan2.Init.BS1 = CAN_BS1_14TQ; hcan2.Init.BS2 = CAN_BS2_6TQ; hcan2.Init.TTCM = DISABLE; hcan2.Init.ABOM = ENABLE; hcan2.Init.AWUM = DISABLE; hcan2.Init.NART = ENABLE; hcan2.Init.RFLM = DISABLE; hcan2.Init.TXFP = DISABLE; HAL_CAN_Init(&hcan2); /*##-2- Configure the CAN Filter ###########################################*/ sFilterConfig.FilterNumber = 14; sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT; sFilterConfig.FilterIdHigh = (((uint16_t) ucCANNodeId) << 5);; sFilterConfig.FilterIdLow = (((uint16_t) ucCANNodeId) << 5); sFilterConfig.FilterMaskIdHigh = ((uint16_t) 0x07E0); sFilterConfig.FilterMaskIdLow = ((uint16_t) 0x07E0); sFilterConfig.FilterFIFOAssignment = CAN_FIFO0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.BankNumber = 14; HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig); } void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) { GPIO_InitTypeDef GPIO_InitStruct; if(hcan->Instance==CAN2) { /* USER CODE BEGIN CAN2_MspInit 0 */ /* USER CODE END CAN2_MspInit 0 */ /* Peripheral clock enable */ __CAN2_CLK_ENABLE(); __CAN1_CLK_ENABLE(); /**CAN2 GPIO Configuration PB5 ------> CAN2_RX PB6 ------> CAN2_TX */ GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_CAN2; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn); HAL_NVIC_SetPriority(CAN2_RX1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(CAN2_RX1_IRQn); HAL_NVIC_SetPriority(CAN2_SCE_IRQn, 0, 0); HAL_NVIC_EnableIRQ(CAN2_SCE_IRQn); /* USER CODE BEGIN CAN2_MspInit 1 */ /* USER CODE END CAN2_MspInit 1 */ } } In the main function: /*##-3- Start the Transmission process #####################################*/ hcan2.pTxMsg->StdId = 0x11; hcan2.pTxMsg->RTR = CAN_RTR_DATA; hcan2.pTxMsg->IDE = CAN_ID_STD; hcan2.pTxMsg->DLC = 2; hcan2.pTxMsg->Data[0] = 0xCA; hcan2.pTxMsg->Data[1] = 0xFE; HAL_CAN_Receive_IT(&hcan2, 0); do{ TimerSwManagementThroughRTC(); if(TestTimerRtc(RTC_100mS)) { if(HAL_CAN_GetState(&hcan2) == HAL_CAN_STATE_READY) { if(HAL_CAN_Transmit(&hcan2, 10) != HAL_OK) { /* Transmition Error */ uiX++; uiCANErrorCode = HAL_CAN_GetError(&hcan2); uiCANState = HAL_CAN_GetState(&hcan2); } } if(HAL_CAN_GetState(&hcan2) != HAL_CAN_STATE_READY) { uiX++; } if(HAL_CAN_GetState(&hcan2) != HAL_CAN_STATE_READY) { uiY++; } } In the stm32f4xx_it.c module /** * @brief This function handles CAN2 TX interrupts. */ void CAN2_TX_IRQHandler(void) { /* USER CODE BEGIN CAN2_TX_IRQn 0 */ /* USER CODE END CAN2_TX_IRQn 0 */ HAL_CAN_IRQHandler(&hcan2); /* USER CODE BEGIN CAN2_TX_IRQn 1 */ /* USER CODE END CAN2_TX_IRQn 1 */ } /** * @brief This function handles CAN2 RX0 interrupts. */ void CAN2_RX0_IRQHandler(void) { /* USER CODE BEGIN CAN2_RX0_IRQn 0 */ /* USER CODE END CAN2_RX0_IRQn 0 */ HAL_CAN_IRQHandler(&hcan2); /* USER CODE BEGIN CAN2_RX0_IRQn 1 */ /* USER CODE END CAN2_RX0_IRQn 1 */ } /** * @brief This function handles CAN2 RX1 interrupt. */ void CAN2_RX1_IRQHandler(void) { /* USER CODE BEGIN CAN2_RX1_IRQn 0 */ /* USER CODE END CAN2_RX1_IRQn 0 */ HAL_CAN_IRQHandler(&hcan2); /* USER CODE BEGIN CAN2_RX1_IRQn 1 */ /* USER CODE END CAN2_RX1_IRQn 1 */ } /** * @brief This function handles CAN2 SCE interrupt. */ void CAN2_SCE_IRQHandler(void) { /* USER CODE BEGIN CAN2_SCE_IRQn 0 */ /* USER CODE END CAN2_SCE_IRQn 0 */ HAL_CAN_IRQHandler(&hcan2); /* USER CODE BEGIN CAN2_SCE_IRQn 1 */ /* USER CODE END CAN2_SCE_IRQn 1 */ }