问题:最近用stm32mp1 MCU CAN开发,但是配置好代码后,发现can发送有问题,定义有三组buf数据,can发送 始终只能发送一组,换别的组数据始终不发送。下面是三组定义的数据;can始终只能发送TxData0
uint8_t TxData1[] = {0x10, 0x32, 0x54, 0x76, 0x98, 0x00, 0x11, 0x22};
uint8_t TxData3[] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x66};
uint8_t TxData0[] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x22, 0x56};
can代码配置
1.can初始化配置,其中设置can频率为20M/(seg1+seg2+1)=500k
- hfdcan1.Instance = FDCAN1;
- hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
- hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;//FDCAN_MODE_EXTERNAL_LOOPBACK;
- hfdcan1.Init.AutoRetransmission = DISABLE;
- hfdcan1.Init.TransmitPause = DISABLE;
- hfdcan1.Init.ProtocolException = DISABLE;
- hfdcan1.Init.NominalPrescaler = 1;
- hfdcan1.Init.NominalSyncJumpWidth = 1;
- hfdcan1.Init.NominalTimeSeg1 = 35;
- hfdcan1.Init.NominalTimeSeg2 = 12;
- hfdcan1.Init.DataPrescaler = 1;
- hfdcan1.Init.DataSyncJumpWidth = 1;
- hfdcan1.Init.DataTimeSeg1 = 1;
- hfdcan1.Init.DataTimeSeg2 = 1;
- hfdcan1.Init.MessageRAMOffset = 0;
- hfdcan1.Init.StdFiltersNbr = 1;
- hfdcan1.Init.ExtFiltersNbr = 0;
- hfdcan1.Init.RxFifo0ElmtsNbr = 1;
- hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
- hfdcan1.Init.RxFifo1ElmtsNbr = 1;
- hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
- hfdcan1.Init.RxBuffersNbr = 8;
- hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
- hfdcan1.Init.TxEventsNbr = 0;
- hfdcan1.Init.TxBuffersNbr = 8;
- hfdcan1.Init.TxFifoQueueElmtsNbr =8;
- hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
- hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
- if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
- {
- Error_Handler();
- }
复制代码 2.can滤波器设置和发送数据设置
- /* USER CODE BEGIN 2 */
- /*##-1 Configure the FDCAN filters ########################################*/
- /* Configure standard ID reception filter to Rx FIFO 0 */
- sFilterConfig.IdType = FDCAN_STANDARD_ID;
- sFilterConfig.FilterIndex = 0;
- sFilterConfig.FilterType = FDCAN_FILTER_MASK;
- sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
- sFilterConfig.FilterID1 = 0x444;
- sFilterConfig.FilterID2 = 0x555;
- if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE END 2 */
- /*##-3 Transmit messages ##################################################*/
- /* Add message to Tx FIFO */
- TxHeader.Identifier = 0x444;
- TxHeader.IdType = FDCAN_STANDARD_ID;
- TxHeader.TxFrameType = FDCAN_DATA_FRAME;
- TxHeader.DataLength = FDCAN_DLC_BYTES_8;
- TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
- TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
- TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
- TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
- TxHeader.MessageMarker = 0;
- if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData0) != HAL_OK)
- {
- Error_Handler();
- }
复制代码 3.发现HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData0)这个函数第三个参数为TxData0就可以发送,如果换上TxData1或者其他始终发送不了,请各位大神看看这是什么原因?
|
代码也没别的东西呀,上面贴出来的是全部的can代码,看过几次了,不知道问题出在那里,但是我把TxData0里面的数据改一下也不能发送,不改不换都可以发送,真心不知道问题出在哪?
应该不是数组名的问题,是里面的数据如不变把数组名改一下,比如TxData5都是可以发送的,关键是里面的数据不能改,改2个可以,改三个就发送不了了
核心和外设都是一样的呀,cubemx配置分配就行了呀
\STM32Cube_FW_MP1_V1.2.0\Projects\STM32MP157C-DK2\Examples\FDCAN\FDCAN_Loopback\STM32CubeIDE
STM32CubeMP1 package v1.2.0可以在下面链接下载:
http://st.com/content/ccc/resour ... 2cubemp1_v1-2-0.zip
评分
查看全部评分