- UID
- 1029342
- 性别
- 男
|
7 与CAN发送有关的固件发送接口发送接口如下:
[cpp] view plaincopy
- /**
- * @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 plaincopy
- /**
- * @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 plaincopy
- 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);
|
|