1、使用新版HAL库中的HAL_CAN_AddTxMessage发送就死机看库文件注释中有说明
/**
* @brief Add a message to the first free Tx mailbox and activate the
* corresponding transmission request.
* @param hcan pointer to a CAN_HandleTypeDef structure that contains
* the configuration information for the specified CAN.
* @param pHeader pointer to a CAN_TxHeaderTypeDef structure.
* @param aData array containing the payload of the Tx frame.
* @param pTxMailbox pointer to a variable where the function will return
* the TxMailbox used to store the Tx message.
* This parameter can be a value of @ARG CAN_Tx_Mailboxes.
* @retval HAL status
*/
这个是因为楼主发送函数的参数写错了,最后一个参数,要自己定义一个变量,然后取地址使用
楼主的是:
HAL_CAN_AddTxMessage(&hcan1,&TxMessage1,TR_BUF,(uint32_t*)CAN_TX_MAILBOX0);
修改为:
int my_pTxMailbox;
HAL_CAN_AddTxMessage(&hcan1,&TxMessage1,TR_BUF,(uint32_t*)&my_pTxMailbox)
这里面的最后一个参数就相当于一个返回值之类的 |