1.7.0版HAL库的can连续发送时邮箱会满。如何解决。CAN_AddTxMes...
把cubemx升级到5.1.0了,顺便把f1的hal库版本升级到1.7.0了。看介绍说can部分做了修改。结果遇到了问题,本想在for循环里发送5帧,结果发送3帧后就不发送了。
调用的是CAN_AddTxMessage()函数,请教该如何操作确保顺利发送?尝试加了个延时倒是能解决,但不想空等啊。
发之前先查询一下 邮箱是否满了,满了就等一下再发
while( HAL_CAN_GetTxMailboxesFreeLevel( &hcan1 ) == 0 );
HAL_CAN_AddTxMessage(&hcan1, &TxHeader, pTxMsg->Data, &TxMailbox); 谢谢,可以了。
顺便请教下,CAN_AddTxMessage()这个函数的最后一个参数,在什么情况下才会用到? 本帖最后由 westzg 于 2019-2-28 10:40 编辑
有三个发送邮箱,&TxMailbox 标记了成功写入到那个发送邮箱
我才发现我项目用的发送函数HAL_CAN_Transmit()
在新库函数中已经变成CAN_AddTxMessage():L 可以考虑用中断方式发送。 安 发表于 2019-2-28 16:23
可以考虑用中断方式发送。
新函数库的说明是:
*** Interrupt mode operation ***
================================
[..]
(#) Notifications are activated using HAL_CAN_ActivateNotification()
function. Then, the process can be controlled through the
available user callbacks: HAL_CAN_xxxCallback(), using same APIs
HAL_CAN_GetRxMessage() and HAL_CAN_AddTxMessage().
(#) Notifications can be deactivated using
HAL_CAN_DeactivateNotification() function.
(#) Special care should be taken for CAN_IT_RX_FIFO0_MSG_PENDING and
CAN_IT_RX_FIFO1_MSG_PENDING notifications. These notifications trig
the callbacks HAL_CAN_RxFIFO0MsgPendingCallback() and
HAL_CAN_RxFIFO1MsgPendingCallback(). User has two possible options
here.
(++) Directly get the Rx message in the callback, using
HAL_CAN_GetRxMessage().
(++) Or deactivate the notification in the callback without
getting the Rx message. The Rx message can then be got later
using HAL_CAN_GetRxMessage(). Once the Rx message have been
read, the notification can be activated again.
函数名称不像以前那样HAL_CAN_Transmit()变成HAL_CAN_Transmit_IT() 奏奏奏 发表于 2019-2-28 21:06
新函数库的说明是:
*** Interrupt mode operation ***
================================
再变化,本质还是不会改变的。只不过我们的使用方式会修改一下。 请问这个解决办法while循环判断,跟普通的if模式有什么区别,下面这种就没法正常的发消息if(HAL_CAN_GetTxMailboxesFreeLevel(hcan))
{
header.StdId=ID;
header.IDE = CAN_ID_STD;
header.RTR = CAN_RTR_DATA;
header.DLC=8;
//header.TransmitGlobalTime = DISABLE; 少了一行HAL_CAN_AddTxMessage(hcan,&header,pData,(uint32_t*)CAN_TX_MAILBOX0);
页:
[1]
2