完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
滤波器配置
void FDCAN1_Config(uint8_t SelectDevice,uint32_t AcceptCode,uint32_t AcceptMask) { FDCAN_FilterTypeDef sFilterConfig; if(AcceptCode>0x7FF) { /* Configure Rx filter */ sFilterConfig.IdType = FDCAN_EXTENDED_ID; sFilterConfig.FilterIndex = 0; sFilterConfig.FilterType = FDCAN_FILTER_MASK; sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; sFilterConfig.FilterID1 = AcceptCode; sFilterConfig.FilterID2 = AcceptMask; if (HAL_FDCAN_ConfigFilter( hfdcan1, sFilterConfig) != HAL_OK) { //Error_Handler(); } } else { /* Configure Rx filter */ sFilterConfig.IdType = FDCAN_STANDARD_ID; sFilterConfig.FilterIndex = 0; sFilterConfig.FilterType = FDCAN_FILTER_MASK; sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; sFilterConfig.FilterID1 = AcceptCode; sFilterConfig.FilterID2 = AcceptMask; if (HAL_FDCAN_ConfigFilter( hfdcan1, sFilterConfig) != HAL_OK) { //Error_Handler(); } } /* Configure global filter: Filter all remote frames with STD and EXT ID Reject non matching frames with STD ID and EXT ID */ if (HAL_FDCAN_ConfigGlobalFilter( hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK) { //Error_Handler(); } if (HAL_FDCAN_ActivateNotification( hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK) { //Error_Handler(); } if (HAL_FDCAN_ConfigTxDelayCompensation( hfdcan1, 5, 0) != HAL_OK) { //Error_Handler(); } if (HAL_FDCAN_EnableTxDelayCompensation( hfdcan1) != HAL_OK) { //Error_Handler(); } /* Start the FDCAN module */ if (HAL_FDCAN_Start( hfdcan1) != HAL_OK) { //Error_Handler(); } if(SelectDevice) //CANFD_BUS { TxHeader.BitRateSwitch = FDCAN_BRS_ON; TxHeader.FDFormat = FDCAN_FD_CAN; } else //CAN_BUS { TxHeader.BitRateSwitch = FDCAN_BRS_OFF; TxHeader.FDFormat = FDCAN_CLASSIC_CAN; } TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS; TxHeader.MessageMarker = 0; // // HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 5, 0); // // HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn); } 初始化 void MX_FDCAN1_Init(uint8_t CAN_Filter) { hfdcan1.Instance = FDCAN1; hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV8; //系统时钟160MHz,FDCAN内核时钟20MHz hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS; hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; hfdcan1.Init.AutoRetransmission = DISABLE; hfdcan1.Init.TransmitPause = DISABLE; hfdcan1.Init.ProtocolException = DISABLE; hfdcan1.Init.NominalPrescaler = 1; hfdcan1.Init.NominalSyncJumpWidth = 8; hfdcan1.Init.NominalTimeSeg1 = 0x1F; hfdcan1.Init.NominalTimeSeg2 = 8; hfdcan1.Init.DataPrescaler = 1; hfdcan1.Init.DataSyncJumpWidth = 4; hfdcan1.Init.DataTimeSeg1 = 5; hfdcan1.Init.DataTimeSeg2 = 4; if(CAN_Filter) { hfdcan1.Init.StdFiltersNbr = 0;//顺序0 hfdcan1.Init.ExtFiltersNbr = 1;//顺序1 } else { hfdcan1.Init.StdFiltersNbr = 1;//顺序0 hfdcan1.Init.ExtFiltersNbr = 0;//顺序1 } hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION; if (HAL_FDCAN_Init( hfdcan1) != HAL_OK) { //Error_Handler(); } } 中断处理 void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) { uint16_t numBytes; uint8_t dataPayload[64] = {0}; // Used to store the received data uint8_t i; if((RxFifo0ITs FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET) { // test ^= 1; // CAN1_LED(test); /* Retrieve Rx messages from RX FIFO0 */ if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, RxHeader, dataPayload) != HAL_OK) { //Error_Handler(); } if (hfdcan->Instance == FDCAN1) { numBytes = RxHeader.DataLength>>16; if (RxHeader.FDFormat)//CANFD_BUS { switch(numBytes) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: memcpy(RxCANFDData, dataPayload, numBytes); break; case 9: memcpy(RxCANFDData, dataPayload, 12); break; case 10: memcpy(RxCANFDData, dataPayload, 16); break; case 11: memcpy(RxCANFDData, dataPayload, 20); break; case 12: memcpy(RxCANFDData, dataPayload, 24); break; case 13: memcpy(RxCANFDData, dataPayload, 32); break; case 14: memcpy(RxCANFDData, dataPayload, 48); break; case 15: memcpy(RxCANFDData, dataPayload, 64); break; } canfd_receive_flag = 1; CANFDLED_Memory = 1; } else//CANFD_BUS { memcpy(RxCANData, dataPayload, numBytes); can_receive_flag = 1; CANLED_Memory = 1; } //FDFormat HAL_FDCAN_ActivateNotification( hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0); }//FDCAN1 } } 有那位大神知道是什么问题 |
|
相关推荐
1个回答
|
|
1。通过启用FDCAN外围设备并设置所需参数(如位定时、帧格式等)来配置FDCAN外围。此步骤确保FDCAN模块已准备好接收数据。
2.通过设置接受代码和接受掩码来配置FDCAN过滤器。接受代码确定过滤器将接受哪些消息,而接受掩码指定接受代码中的哪些位是相关的。 3.启用FDCAN接收中断。当接收到与过滤器配置匹配的有效消息时,会触发此中断。 4.实现FDCAN接收中断的中断处理程序。此处理程序负责读取接收到的消息并相应地进行处理。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1810 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1631 浏览 1 评论
1098 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
737 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1687 浏览 2 评论
1945浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
750浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
584浏览 3评论
604浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
568浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 14:13 , Processed in 0.693138 second(s), Total 48, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号