标题:
STM32之CAN---发送管理分析(4)
[打印本页]
作者:
yuyang911220
时间:
2014-12-22 17:29
标题:
STM32之CAN---发送管理分析(4)
7 与CAN发送有关的固件发送接口发送接口如下:
[cpp]
view plain
copy
/**
* @brief Initiates and transmits a CAN frame message.
* @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
* @param TxMessage: pointer to a structure which contains CAN Id, CAN DLC and CAN data.
* @retval The number of the mailbox that is used for transmission or
* CAN_TxStatus_NoMailBox if there is no empty mailbox.
*/
uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
获取发送状态接口如下:
[cpp]
view plain
copy
/**
* @brief Checks the transmission status of a CAN Frame.
* @param CANx: where x can be 1 or 2 to select the CAN peripheral.
* @param TransmitMailbox: the number of the mailbox that is used for transmission.
* @retval CAN_TxStatus_Ok if the CAN driver transmits the message,
* CAN_TxStatus_Failed in an other case.
*/
uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
8 一个示例
[cpp]
view plain
copy
CanTxMsg TxMessage;
int i;
if(id_fmt == STD_ID)//如果是标准CAN ID
{
TxMessage.StdId = send_frame->id; //设置标准CAN ID
TxMessage.IDE = CAN_ID_STD; //设置IDE为标准CAN ID
}
else
{
TxMessage.StdId = (send_frame->
id >>18) & 0x7FF; //设置扩展CAN ID的标准基本ID部分
TxMessage.ExtId = send_frame->id & 0x3FFFF; //设置扩展CAN ID的扩展ID部分
TxMessage.IDE = CAN_ID_EXT; //设置IDE为扩展CAN ID
}
TxMessage.RTR = CAN_RTR_DATA; //数据帧
TxMessage.DLC = 8; //数据长度
for(i=0;i<8;i++)<br>
{
TxMessage.Data
= send_frame->data_buff
;
}
CAN_Transmit(CAN1,&TxMessage);
作者:
蓝小墨云
时间:
2014-12-22 19:10
哎哟 这个貌似看起来还可以哦
。。你们看看
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0