Ich benutze STM32 Cube HAL driver auf STM32F429 für CAN bus communication zwischen Microcontroller und PCAN View.Ich kann sendet die Nachricten zu PCAn aber kann ich nicht empfangt jedes nachrichten von PCAN.Meine Program ist hier:..All die functions sind preinitalized in andere .C file... Danke #include "stm32f4xx_hal.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ CAN_HandleTypeDef hcan1; CAN_HandleTypeDef hcan2; /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); //static void MX_CAN1_Init(void); static void MX_CAN2_Init(void); static void MX_CAN2Filter(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------* / /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_CAN2_Init(); MX_CAN2Filter(); // MX_CAN1_Init(); /* USER CODE BEGIN 2 */ __GPIOD_CLK_ENABLE(); GPIO_InitTypeDef GPIO_Initpins; GPIO_Initpins.Mode = GPIO_MODE_OUTPUT_PP ; GPIO_Initpins.Pin = GPIO_PIN_5|GPIO_PIN_7; GPIO_Initpins.Pull = GPIO_NOPULL ; HAL_GPIO_Init(GPIOD, &GPIO_Initpins); HAL_GPIO_WritePin(GPIOD, GPIO_PIN_5|GPIO_PIN_7, GPIO_PIN_SET); /* USER CODE END 2 */ /* USER CODE BEGIN 3 */ /* Infinite loop */ // CanTxMsgTypeDef TxMess; // TxMess.StdId = 0x123; // TxMess.DLC = 0x1; // TxMess.Data[0] = 0x12; // TxMess.IDE = CAN_ID_STD; // TxMess.RTR = 0; // hcan2.pTxMsg = &TxMess; //HAL_CAN_Transmit(&hcan2,5); CanRxMsgTypeDef RxMess; //RxMess.FIFONumber = CAN_FIFO0; RxMess.StdId = 0x541; hcan2.pRxMsg = &RxMess; while(1) { HAL_CAN_Receive(&hcan2,CAN_FIFO0,0); } /* USER CODE END 3 */ } /** System Clock Configuration */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; __PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; HAL_RCC_OscConfig(&RCC_OscInitStruct); RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); } /* CAN2 init function */ void MX_CAN2_Init(void) { hcan2.Instance = CAN2; hcan2.Init.Prescaler = 2; hcan2.Init.Mode = CAN_MODE_NORMAL; hcan2.Init.SJW = CAN_SJW_1TQ; hcan2.Init.BS1 = CAN_BS1_5TQ; hcan2.Init.BS2 = CAN_BS2_2TQ; hcan2.Init.TTCM = DISABLE; hcan2.Init.ABOM = DISABLE; hcan2.Init.AWUM = DISABLE; hcan2.Init.NART = DISABLE; hcan2.Init.RFLM = ENABLE; hcan2.Init.TXFP = DISABLE; HAL_CAN_Init(&hcan2); HAL_CAN_Receive_IT(&hcan2,CAN_FIFO0); } void MX_CAN2Filter(void) { CAN_FilterConfTypeDef hcan2filter; //hcan2filter.FilterIdHigh = 0xFFF; //hcan2filter.FilterIdLow = 0x00; //hcan2filter.FilterMaskIdHigh = 0x7FF; //hcan2filter.FilterMaskIdLow = 0x01; hcan2filter.FilterActivation = ENABLE; hcan2filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; hcan2filter.FilterNumber = 0; //hcan2filter.FilterMode = CAN_FILTERMODE_IDLIST; hcan2filter.FilterScale = CAN_FILTERSCALE_32BIT; //hcan2filter.BankNumber = 14; HAL_CAN_ConfigFilter(&hcan2, &hcan2filter); } /** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI */ void MX_GPIO_Init(void) { /* GPIO Ports Clock Enable */ __GPIOH_CLK_ENABLE(); __GPIOB_CLK_ENABLE(); __GPIOA_CLK_ENABLE(); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif
CAN clock eingeschaltet? Wenn Du beim STM32F4 den CAN2 verwendest, dann musst Du ZUSÄTZLICH auch die clk von CAN1 einschalten: __CAN1_CLK_ENABLE(); __CAN2_CLK_ENABLE(); Viele Grüße, Stefan
Ich hatte Schön gemacht..All the functions are initalized in another file and thats why my CAN bus messages are transmitting..Only things the messages are not receiving...
Wenn das Senden funktioniert, dann würde ich mal nach den Filtern schauen. //hcan2filter.FilterIdHigh = 0xFFF; //hcan2filter.FilterIdLow = 0x00; //hcan2filter.FilterMaskIdHigh = 0x7FF; //hcan2filter.FilterMaskIdLow = 0x01; hcan2filter.FilterActivation = ENABLE; hcan2filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; hcan2filter.FilterNumber = 0; //hcan2filter.FilterMode = CAN_FILTERMODE_IDLIST; hcan2filter.FilterScale = CAN_FILTERSCALE_32BIT; Da sind einige Zeilen auskommentiert, soll das so sein? Gruß, Stefan
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.