32 lines
1.2 KiB
C
32 lines
1.2 KiB
C
|
|
#include "by_can.h"
|
|||
|
|
|
|||
|
|
#include <string.h>
|
|||
|
|
#include <assert.h>
|
|||
|
|
|
|||
|
|
uint8_t by_can_send_stdd(uint32_t id, const uint8_t *data, uint8_t len)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
assert(id < 0x7FF);
|
|||
|
|
|
|||
|
|
if (len > 8) {
|
|||
|
|
len = 8;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
uint8_t transmit_mailbox;
|
|||
|
|
can_tx_message_type tx_message_struct;
|
|||
|
|
tx_message_struct.standard_id = id; /* 设置发送数据帧的 ID=0x400 */
|
|||
|
|
tx_message_struct.extended_id = 0; /* 不设置 */
|
|||
|
|
tx_message_struct.id_type = CAN_ID_STANDARD; /* 发送数据帧类型(标准/扩展):标准数据帧 */
|
|||
|
|
tx_message_struct.frame_type = CAN_TFT_DATA; /* 发送帧类型(远程/数据):数据帧 */
|
|||
|
|
tx_message_struct.dlc = len; /* 发送数据长度(0~8):8 */
|
|||
|
|
memcpy(tx_message_struct.data, data, len); /* 复制发送数据 */
|
|||
|
|
transmit_mailbox = can_message_transmit(CAN1, &tx_message_struct); /* 将以上待发送报文写入发送邮箱并请求发送 */
|
|||
|
|
|
|||
|
|
/* 等待该邮箱发送成功—对应邮箱发送成功标志置起 */
|
|||
|
|
while (can_transmit_status_get(CAN1, (can_tx_mailbox_num_type)transmit_mailbox) !=
|
|||
|
|
CAN_TX_STATUS_SUCCESSFUL)
|
|||
|
|
;
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|