Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
CAN总线
stm32F1系列can问题求助
发布于 2019-12-11 09:03:52 浏览:1970
订阅该版
* 本帖最后由 921742079 于 2019-12-11 09:08 编辑 * 买的stm32f103vet6的带can的工控板,自己改的BSP,cubeMX配置管脚以后,测试,无法接收数据,另外一端接的usb转can的分析仪,也拿不到数据,波特率都试过了,都不行,我用的是基于313的rtt,scons --menuconfig里面,关闭了can的硬件过滤器,apb1也看了,是36的,后来发现有人说需要用新的can驱动,然后我复制github的master分支里面的drv_can.c和h,复制到项目的 libraries/HAL_Drivers/下面,但是各种编译出错,怎样才能编译通过?
查看更多
23
个回答
默认排序
按发布时间排序
921742079
2019-12-11
这家伙很懒,什么也没写!
[i=s] 本帖最后由 921742079 于 2019-12-11 10:14 编辑 [/i] 我是直接把master里面的 drv_can.c和drv_can.h 替换原来的老的里面的,之前有帖子说到, ``` 这是由于hal库升级,而之前发布的can驱动基于旧的hal库导致的 ``` 不知道是不是这个原因,也不知道应该从哪里下载新的hal库 编译错误信息如下 ``` In file included from libraries/HAL_Drivers/drv_can.c:14:0: libraries/HAL_Drivers/drv_can.h:40:5: error: unknown type name 'CAN_TxHeaderTypeDef' CAN_TxHeaderTypeDef TxMessage; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.h:41:5: error: unknown type name 'CAN_RxHeaderTypeDef' CAN_RxHeaderTypeDef RxMessage; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.h:43:5: error: unknown type name 'CAN_RxHeaderTypeDef' CAN_RxHeaderTypeDef Rx1Message; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.h:45:5: error: unknown type name 'CAN_FilterTypeDef' CAN_FilterTypeDef FilterConfig; ^~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c: In function 'USB_LP_CAN1_RX0_IRQHandler': libraries/HAL_Drivers/drv_can.c:150:5: error: unknown type name 'CAN_RxHeaderTypeDef' CAN_RxHeaderTypeDef *pRxMsg = RT_NULL; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:163:15: error: request for member 'IDE' in something not a structure or union pRxMsg->IDE = (uint8_t)0x04U & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RIR; ^~ libraries/HAL_Drivers/drv_can.c:163:69: error: 'CAN_RX_FIFO0' undeclared (first use in this function) pRxMsg->IDE = (uint8_t)0x04U & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RIR; ^~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:163:69: note: each undeclared identifier is reported only once for each function it appears in libraries/HAL_Drivers/drv_can.c:164:19: error: request for member 'IDE' in something not a structure or union if (pRxMsg->IDE == CAN_ID_STD) ^~ libraries/HAL_Drivers/drv_can.c:166:19: error: request for member 'StdId' in something not a structure or union pRxMsg->StdId = 0x000007FFU & (hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RIR >> 21U); ^~ libraries/HAL_Drivers/drv_can.c:170:19: error: request for member 'ExtId' in something not a structure or union pRxMsg->ExtId = 0x1FFFFFFFU & (hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RIR >> 3U); ^~ libraries/HAL_Drivers/drv_can.c:173:15: error: request for member 'RTR' in something not a structure or union pRxMsg->RTR = (uint8_t)0x02U & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RIR; ^~ libraries/HAL_Drivers/drv_can.c:175:15: error: request for member 'DLC' in something not a structure or union pRxMsg->DLC = (uint8_t)0x0FU & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RDTR; ^~ libraries/HAL_Drivers/drv_can.c:177:15: error: request for member 'FilterMatchIndex' in something not a structure or union pRxMsg->FilterMatchIndex = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[CAN_RX_FIFO0].RDTR >> 8U); ^~ libraries/HAL_Drivers/drv_can.c: In function 'CAN1_RX1_IRQHandler': libraries/HAL_Drivers/drv_can.c:221:5: error: unknown type name 'CAN_RxHeaderTypeDef' CAN_RxHeaderTypeDef *pRxMsg = NULL; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:234:15: error: request for member 'IDE' in something not a structure or union pRxMsg->IDE = (uint8_t)0x04U & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RIR; ^~ libraries/HAL_Drivers/drv_can.c:234:69: error: 'CAN_RX_FIFO1' undeclared (first use in this function) pRxMsg->IDE = (uint8_t)0x04U & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RIR; ^~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:235:19: error: request for member 'IDE' in something not a structure or union if (pRxMsg->IDE == CAN_ID_STD) ^~ libraries/HAL_Drivers/drv_can.c:237:19: error: request for member 'StdId' in something not a structure or union pRxMsg->StdId = 0x000007FFU & (hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RIR >> 21U); ^~ libraries/HAL_Drivers/drv_can.c:241:19: error: request for member 'ExtId' in something not a structure or union pRxMsg->ExtId = 0x1FFFFFFFU & (hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RIR >> 3U); ^~ libraries/HAL_Drivers/drv_can.c:244:15: error: request for member 'RTR' in something not a structure or union pRxMsg->RTR = (uint8_t)0x02U & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RIR; ^~ libraries/HAL_Drivers/drv_can.c:246:15: error: request for member 'DLC' in something not a structure or union pRxMsg->DLC = (uint8_t)0x0FU & hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RDTR; ^~ libraries/HAL_Drivers/drv_can.c:248:15: error: request for member 'FilterMatchIndex' in something not a structure or union pRxMsg->FilterMatchIndex = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[CAN_RX_FIFO1].RDTR >> 8U); ^~ libraries/HAL_Drivers/drv_can.c: In function 'drv_configure': libraries/HAL_Drivers/drv_can.c:604:5: error: unknown type name 'CAN_FilterTypeDef' CAN_FilterTypeDef *filterConf; ^~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:612:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TimeTriggeredMode' drv_init->TimeTriggeredMode = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:613:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'AutoBusOff' drv_init->AutoBusOff = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:614:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'AutoWakeUp' drv_init->AutoWakeUp = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:615:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'AutoRetransmission' drv_init->AutoRetransmission = ENABLE; ^~ libraries/HAL_Drivers/drv_can.c:616:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'ReceiveFifoLocked' drv_init->ReceiveFifoLocked = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:617:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TransmitFifoPriority' drv_init->TransmitFifoPriority = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:636:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'SyncJumpWidth' drv_init->SyncJumpWidth = BAUD_DATA(SJW, baud_index); ^~ libraries/HAL_Drivers/drv_can.c:637:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TimeSeg1' drv_init->TimeSeg1 = BAUD_DATA(BS1, baud_index); ^~ libraries/HAL_Drivers/drv_can.c:638:13: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TimeSeg2' drv_init->TimeSeg2 = BAUD_DATA(BS2, baud_index); ^~ libraries/HAL_Drivers/drv_can.c:644:9: warning: implicit declaration of function 'HAL_CAN_Start' [-Wimplicit-function-declaration] if (HAL_CAN_Start(&drv_can->CanHandle) != HAL_OK) ^~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:651:15: error: request for member 'FilterBank' in something not a structure or union filterConf->FilterBank = 0; ^~ libraries/HAL_Drivers/drv_can.c:652:15: error: request for member 'FilterMode' in something not a structure or union filterConf->FilterMode = CAN_FILTERMODE_IDMASK; ^~ libraries/HAL_Drivers/drv_can.c:653:15: error: request for member 'FilterScale' in something not a structure or union filterConf->FilterScale = CAN_FILTERSCALE_32BIT; ^~ libraries/HAL_Drivers/drv_can.c:654:15: error: request for member 'FilterIdHigh' in something not a structure or union filterConf->FilterIdHigh = 0x0000; ^~ libraries/HAL_Drivers/drv_can.c:655:15: error: request for member 'FilterIdLow' in something not a structure or union filterConf->FilterIdLow = 0x0000; ^~ libraries/HAL_Drivers/drv_can.c:656:15: error: request for member 'FilterMaskIdHigh' in something not a structure or union filterConf->FilterMaskIdHigh = 0x0000; ^~ libraries/HAL_Drivers/drv_can.c:657:15: error: request for member 'FilterMaskIdLow' in something not a structure or union filterConf->FilterMaskIdLow = 0x0000; ^~ libraries/HAL_Drivers/drv_can.c:658:15: error: request for member 'FilterFIFOAssignment' in something not a structure or union filterConf->FilterFIFOAssignment = CAN_FILTER_FIFO0; ^~ libraries/HAL_Drivers/drv_can.c:659:15: error: request for member 'FilterActivation' in something not a structure or union filterConf->FilterActivation = ENABLE; ^~ libraries/HAL_Drivers/drv_can.c:660:15: error: request for member 'SlaveStartFilterBank' in something not a structure or union filterConf->SlaveStartFilterBank = 14; ^~ libraries/HAL_Drivers/drv_can.c:661:47: warning: passing argument 2 of 'HAL_CAN_ConfigFilter' from incompatible pointer type [-Wincompatible-pointer-types] HAL_CAN_ConfigFilter(&drv_can->CanHandle, filterConf); ^~~~~~~~~~ In file included from board/CubeMX_Config/Inc/stm32f1xx_hal_conf.h:256:0, from libraries/STM32F1xx_HAL/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:46, from libraries/STM32F1xx_HAL/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:218, from board/board.h:15, from libraries/HAL_Drivers/drv_can.h:15, from libraries/HAL_Drivers/drv_can.c:14: libraries/STM32F1xx_HAL/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_can.h:700:19: note: expected 'CAN_FilterConfTypeDef * {aka struct
*}' but argument is of type 'int *' HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig); ^~~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c: In function 'drv_control': libraries/HAL_Drivers/drv_can.c:835:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TimeTriggeredMode' drv_init->TimeTriggeredMode = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:836:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'AutoBusOff' drv_init->AutoBusOff = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:837:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'AutoWakeUp' drv_init->AutoWakeUp = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:838:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'AutoRetransmission' drv_init->AutoRetransmission = ENABLE; ^~ libraries/HAL_Drivers/drv_can.c:839:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'ReceiveFifoLocked' drv_init->ReceiveFifoLocked = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:840:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TransmitFifoPriority' drv_init->TransmitFifoPriority = DISABLE; ^~ libraries/HAL_Drivers/drv_can.c:842:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'SyncJumpWidth' drv_init->SyncJumpWidth = BAUD_DATA(SJW, baud_index); ^~ libraries/HAL_Drivers/drv_can.c:843:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TimeSeg1' drv_init->TimeSeg1 = BAUD_DATA(BS1, baud_index); ^~ libraries/HAL_Drivers/drv_can.c:844:21: error: 'CAN_InitTypeDef {aka struct
}' has no member named 'TimeSeg2' drv_init->TimeSeg2 = BAUD_DATA(BS2, baud_index); ^~ libraries/HAL_Drivers/drv_can.c: In function 'drv_sendmsg': libraries/HAL_Drivers/drv_can.c:890:5: error: unknown type name 'CAN_TxHeaderTypeDef' CAN_TxHeaderTypeDef *pTxMsg = RT_NULL; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:933:15: error: request for member 'IDE' in something not a structure or union pTxMsg->IDE = CAN_ID_STD; ^~ libraries/HAL_Drivers/drv_can.c:934:15: error: request for member 'StdId' in something not a structure or union pTxMsg->StdId = pmsg->id; ^~ libraries/HAL_Drivers/drv_can.c:935:15: error: request for member 'ExtId' in something not a structure or union pTxMsg->ExtId = 0xFFFFFFFFU; ^~ libraries/HAL_Drivers/drv_can.c:939:15: error: request for member 'IDE' in something not a structure or union pTxMsg->IDE = CAN_ID_EXT; ^~ libraries/HAL_Drivers/drv_can.c:940:15: error: request for member 'StdId' in something not a structure or union pTxMsg->StdId = 0xFFFFFFFFU; ^~ libraries/HAL_Drivers/drv_can.c:941:15: error: request for member 'ExtId' in something not a structure or union pTxMsg->ExtId = pmsg->id; ^~ libraries/HAL_Drivers/drv_can.c:947:15: error: request for member 'RTR' in something not a structure or union pTxMsg->RTR = CAN_RTR_DATA; ^~ libraries/HAL_Drivers/drv_can.c:951:15: error: request for member 'RTR' in something not a structure or union pTxMsg->RTR = CAN_RTR_REMOTE; ^~ libraries/HAL_Drivers/drv_can.c:954:11: error: request for member 'DLC' in something not a structure or union pTxMsg->DLC = pmsg->len; ^~ libraries/HAL_Drivers/drv_can.c:959:15: error: request for member 'IDE' in something not a structure or union if (pTxMsg->IDE == CAN_ID_STD) ^~ libraries/HAL_Drivers/drv_can.c:962:58: error: request for member 'StdId' in something not a structure or union hcan->Instance->sTxMailBox[boxno].TIR |= ((pTxMsg->StdId << CAN_TI0R_STID_Pos) | \ ^~ libraries/HAL_Drivers/drv_can.c:963:23: error: request for member 'RTR' in something not a structure or union pTxMsg->RTR); ^~ libraries/HAL_Drivers/drv_can.c:968:57: error: request for member 'ExtId' in something not a structure or union hcan->Instance->sTxMailBox[boxno].TIR |= (pTxMsg->ExtId << CAN_TI0R_EXID_Pos) | \ ^~ libraries/HAL_Drivers/drv_can.c:969:23: error: request for member 'IDE' in something not a structure or union pTxMsg->IDE | ^~ libraries/HAL_Drivers/drv_can.c:970:23: error: request for member 'RTR' in something not a structure or union pTxMsg->RTR; ^~ libraries/HAL_Drivers/drv_can.c:973:11: error: request for member 'DLC' in something not a structure or union pTxMsg->DLC &= (uint8_t)0x0000000FU; ^~ libraries/HAL_Drivers/drv_can.c:975:53: error: request for member 'DLC' in something not a structure or union hcan->Instance->sTxMailBox[boxno].TDTR |= pTxMsg->DLC; ^~ libraries/HAL_Drivers/drv_can.c: In function 'drv_recvmsg': libraries/HAL_Drivers/drv_can.c:995:5: error: unknown type name 'CAN_RxHeaderTypeDef' CAN_RxHeaderTypeDef *pRxMsg = RT_NULL; ^~~~~~~~~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:1002:10: error: 'CAN_RX_FIFO0' undeclared (first use in this function) case CAN_RX_FIFO0: ^~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:1006:10: error: 'CAN_RX_FIFO1' undeclared (first use in this function) case CAN_RX_FIFO1: ^~~~~~~~~~~~ libraries/HAL_Drivers/drv_can.c:1017:29: error: request for member 'IDE' in something not a structure or union if (CAN_ID_STD == pRxMsg->IDE) ^~ libraries/HAL_Drivers/drv_can.c:1020:26: error: request for member 'StdId' in something not a structure or union pmsg->id = pRxMsg->StdId; ^~ libraries/HAL_Drivers/drv_can.c:1022:34: error: request for member 'IDE' in something not a structure or union else if (CAN_ID_EXT == pRxMsg->IDE) ^~ libraries/HAL_Drivers/drv_can.c:1025:26: error: request for member 'ExtId' in something not a structure or union pmsg->id = pRxMsg->ExtId; ^~ libraries/HAL_Drivers/drv_can.c:1028:31: error: request for member 'RTR' in something not a structure or union if (CAN_RTR_DATA == pRxMsg->RTR) ^~ libraries/HAL_Drivers/drv_can.c:1032:38: error: request for member 'RTR' in something not a structure or union else if (CAN_RTR_REMOTE == pRxMsg->RTR) ^~ libraries/HAL_Drivers/drv_can.c:1037:23: error: request for member 'DLC' in something not a structure or union pmsg->len = pRxMsg->DLC; ^~ libraries/HAL_Drivers/drv_can.c:1039:23: error: request for member 'FilterMatchIndex' in something not a structure or union pmsg->hdr = pRxMsg->FilterMatchIndex; ^~ scons: *** [libraries/HAL_Drivers/drv_can.o] Error 1 scons: building terminated because of errors. 终端进程已终止,退出代码: 2 ```
921742079
2019-12-11
这家伙很懒,什么也没写!
[i=s] 本帖最后由 921742079 于 2019-12-11 10:25 编辑 [/i] 用原版的,编译可以通过,但是在usb-can分析仪那边,看不到数据,我开发板换了两个了,can分析器也换了两个了,上逻辑分析仪,大概这样[attach]12655[/attach] [attach]12656[/attach] channel 0对应H接线柱 测试代码如下 ``` /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2019-06-25 misonyo first implementation. */ /* * 程序清单:这是一个 CAN 设备使用例程 * 例程导出了 can_sample 命令到控制终端 * 命令调用格式:can_sample can2 * 命令解释:命令第二个参数是要使用的 CAN 设备名称,为空则使用默认的 CAN 设备 * 程序功能:通过 CAN 设备发送一帧,并创建一个线程接收数据然后打印输出。 */ #include
#include "rtdevice.h" #define CAN_DEV_NAME "can1" /* CAN 设备名称 */ static struct rt_semaphore rx_sem; /* 用于接收消息的信号量 */ static rt_device_t can_dev; /* CAN 设备句柄 */ /* 接收数据回调函数 */ static rt_err_t can_rx_call(rt_device_t dev, rt_size_t size) { /* CAN 接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */ rt_sem_release(&rx_sem); return RT_EOK; } static void can_rx_thread(void *parameter) { int i; rt_err_t res; struct rt_can_msg rxmsg = {0}; /* 设置接收回调函数 */ rt_device_set_rx_indicate(can_dev, can_rx_call); #ifdef RT_CAN_USING_HDR struct rt_can_filter_item items[5] = { RT_CAN_FILTER_ITEM_INIT(0x100, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x100~0x1ff,hdr为-1,设置默认过滤表 */ RT_CAN_FILTER_ITEM_INIT(0x300, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x300~0x3ff,hdr为-1 */ RT_CAN_FILTER_ITEM_INIT(0x211, 0, 0, 0, 0x7ff, RT_NULL, RT_NULL), /* std,match ID:0x211,hdr为-1 */ RT_CAN_FILTER_STD_INIT(0x486, RT_NULL, RT_NULL), /* std,match ID:0x486,hdr为-1 */ {0x555, 0, 0, 0, 0x7ff, 7,} /* std,match ID:0x555,hdr为7,指定设置7号过滤表 */ }; struct rt_can_filter_config cfg = {5, 1, items}; /* 一共有5个过滤表 */ /* 设置硬件过滤表 */ res = rt_device_control(can_dev, RT_CAN_CMD_SET_FILTER, &cfg); RT_ASSERT(res == RT_EOK); #endif while (1) { /* hdr值为-1,表示直接从uselist链表读取数据 */ rxmsg.hdr = -1; /* 阻塞等待接收信号量 */ rt_sem_take(&rx_sem, RT_WAITING_FOREVER); /* 从CAN读取一帧数据 */ rt_device_read(can_dev, 0, &rxmsg, sizeof(rxmsg)); /* 打印数据ID及内容 */ rt_kprintf("ID:%x ", rxmsg.id); for (i = 0; i < 8; i++) { rt_kprintf("%2x ", rxmsg.data[i]); } rt_kprintf("\n"); } } int can_sample(int argc, char *argv[]) { struct rt_can_msg msg = {0}; rt_err_t res; rt_size_t size; rt_thread_t thread; char can_name[RT_NAME_MAX]; if (argc == 2) { rt_strncpy(can_name, argv[1], RT_NAME_MAX); } else { rt_strncpy(can_name, CAN_DEV_NAME, RT_NAME_MAX); } can_dev = rt_device_find(can_name); if (!can_dev) { rt_kprintf("find %s failed!\n", can_name); return RT_ERROR; } /* 初始化CAN接收信号量 */ rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO); /* 以中断接收及发送方式打开CAN设备 */ res = rt_device_open(can_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX); RT_ASSERT(res == RT_EOK); thread = rt_thread_create("can_rx", can_rx_thread, RT_NULL, 1024, 25, 10); if (thread != RT_NULL) { rt_thread_startup(thread); } else { rt_kprintf("create can_rx thread failed!\n"); } msg.id = 0x78; /* ID为0x78 */ msg.ide = RT_CAN_STDID; /* 标准格式 */ msg.rtr = RT_CAN_DTR; /* 数据帧 */ msg.len = 8; /* 数据长度为8 */ /* 待发送的8字节数据 */ msg.data[0] = 0x00; msg.data[1] = 0x11; msg.data[2] = 0x22; msg.data[3] = 0x33; msg.data[4] = 0x44; msg.data[5] = 0x55; msg.data[6] = 0x66; msg.data[7] = 0x77; /* 发送一帧CAN数据 */ size = rt_device_write(can_dev, 0, &msg, sizeof(msg)); if (size == 0) { rt_kprintf("can dev write data failed!\n"); } return res; } /* 导出到 msh 命令列表中 */ MSH_CMD_EXPORT(can_sample, can device sample); ``` hdr关闭了,没启用
921742079
2019-12-11
这家伙很懒,什么也没写!
逻辑分析仪几次测试,出来的图形都不太一样 [attach]12658[/attach] [attach]12659[/attach] [attach]12660[/attach] [attach]12661[/attach]
921742079
2019-12-11
这家伙很懒,什么也没写!
又测了几次,下面这种波形出现次数比较多,但是有时候解码有数据,但是数据也是错的,大部分时候decode以后没有数据 [attach]12662[/attach]
921742079
2019-12-11
这家伙很懒,什么也没写!
这样的时钟配置有没有问题? [attach]12663[/attach]
921742079
2019-12-11
这家伙很懒,什么也没写!
这是hdr [attach]12664[/attach]
egrias
2019-12-11
这家伙很懒,什么也没写!
HSI精度低, 通信不要使用.
921742079
2019-12-11
这家伙很懒,什么也没写!
>HSI精度低, 通信不要使用. --- 测试问题应该不大吧?不是生产,另外,现在换了hse也一样
egrias
2019-12-11
这家伙很懒,什么也没写!
我近期也在学习RT-Thread, 拿了个板子移植了下, can可以发送数据. 工程是用ENV生成的, drv_can.c和drv_can.h从github上找的: /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-08-05 Xeon Xu the first version * 2019-01-22 YLZ port from stm324xx-HAL to bsp stm3210x-HAL * 2019-02-19 YLZ add support EXTID RTR Frame. modify send, recv functions. * fix bug.port to BSP [stm32] */
921742079
2019-12-11
这家伙很懒,什么也没写!
>我近期也在学习RT-Thread, 拿了个板子移植了下, can可以发送数据. 工程是用ENV生成的, drv_can.c和drv_can. ... --- 和我的从rtt的git的master里面找的一样,然后我替换了libraries/STM32F4xx_HAL/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c 现在项目能跑,但是数据还是不通,你那边是板子对板子还是板子对分析器啊? 我的drv_can.c开头注释 ``` /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-08-05 Xeon Xu the first version * 2019-01-22 YLZ port from stm324xx-HAL to bsp stm3210x-HAL * 2019-02-19 YLZ add support EXTID RTR Frame. modify send, recv functions. * fix bug.port to BSP [stm32] */ ```
撰写答案
登录
注册新账号
关注者
0
被浏览
2k
关于作者
921742079
这家伙很懒,什么也没写!
提问
42
回答
145
被采纳
3
关注TA
发私信
相关问题
1
我也来传一个CANOpen移植,RTT+STM32F107+CanOpenNode
2
谁有STM32裸跑的CANopen程序啊???
3
CAN驱动程序框架
4
CAN驱动接口如何规范一下
5
RTT无法进入线程.Cannot access Memory
6
编译提示arm-none-eabi/bin/ld: cannot find crt0.o: No such file o
7
rtt 2.1.0 正式版 mdk4 bsp/stm32 编译canapp.c错误
8
STM32F10XCAN驱动使用的问题
9
2.1版本stm32f10x分支bxcan驱动波特率设置的bug
10
rtthread2.1.0下,找不到can1设备
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
开源共生 商业共赢 | RT-Thread 2024开发者大会议程正式发布!
2
【24嵌入式设计大赛】基于RT-Thread星火一号的智慧家居系统
3
RT-Thread EtherKit开源以太网硬件正式发布
4
如何在master上的BSP中添加配置yml文件
5
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
rt_mq_消息队列_msg_queue
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
a1012112796
20
个答案
3
次被采纳
张世争
11
个答案
3
次被采纳
踩姑娘的小蘑菇
7
个答案
3
次被采纳
rv666
9
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
RTT_逍遥
1
篇文章
6
次点赞
大龄码农
1
篇文章
5
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部