嵌入式技术william hill官网
直播中

张英

7年用户 1407经验值
私信 关注
[问答]

CAN rt_device_write()函数返回值为0有哪位大神可以解答一下呢?

rt_size_t can_sendmsg(uint8_t *data)
{
struct rt_can_msg msg = {0};

rt_memcpy(msg.data, data, sizeof(msg));
msg.id = 0x78; /* ID 为 0x78 /
msg.ide = RT_CAN_STDID; /
标准格式 /
msg.rtr = RT_CAN_DTR; /
数据帧 /
msg.len = 8; /
数据长度为 8 */
uint8_t size = rt_device_write(can_dev, 0, &msg, sizeof(msg));
if (size == 0)
{
rt_kprintf("can dev write data failed!
");
}
return size;
}

rt_device_write的返回值为0,有哪位大神可以解答一下

回帖(3)

张英

2023-2-13 14:45:10
产品从FreeRTOS移植到RTT上,遇到问题了,感觉RTT的can驱动问题很多啊dizzy
举报

张英

2023-2-13 14:45:16
已经找到问题了,drv_can.c中默认的can波特率配置中BS1 BS2设置的不对,修改后就可以了
举报

张英

2023-2-13 14:45:22
static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
{
// {CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 3)},
// {CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ | CAN_BS2_5TQ | 4)},
// // {CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 6)},

// {CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 12)},
// {CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 24)},
// {CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 30)},
// {CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 60)},
// {CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 150)},
//// {CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 300)}

{CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 3)},
{CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 4)},
{CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 6)},
{CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 12)},
{CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 24)},
{CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 30)},
{CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 60)},
{CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 150)},
{CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_6TQ  | CAN_BS2_7TQ | 300)}
举报

更多回帖

发帖
×
20
完善资料,
赚取积分