1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
【MYD-JX8MMA7】 (四)CAN通讯理论 因为在经过两天的时间研究can通讯发现,can通讯存在问题,后咨询厂家技术,厂家技术表示此板子系统里没有配置can通讯相关内容。所以一下是理论内容 一、硬件电路 1、CAN-IO 首先是查硬件用户手册,板载没有CAN通讯芯片,所以需要查下预留的CAN通讯接口,还可查看原理图,找到CAN通讯接口,还需要找到供电电源。 2、CAN硬件电路 CAN硬件电路是一个比较标准的电路,在这里使用的是NXP1042CAN通讯芯片。 3、CAN分析仪 CAN分析仪用于电脑和开发板通讯的测试使用,在此使用的是创新科技的CAN分析仪。国产CAN分析仪虽然稳定性不够好,但是很实惠啊。 二、软件代码 1.代码文件.c #include <can_config.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <signal.h> #include <libgen.h> #include <getopt.h> #include <limits.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/uio.h> #include <sys/ioctl.h> #include <net/if.h> #include <linux/can.h> #include <linux/can/raw.h> extern int optind, opterr, optopt; static int running = 1; enum { VERSION_OPTION = CHAR_MAX + 1, }; void print_usage(char *prg) { fprintf(stderr, "Usage: %s [] [Options]\n" "\n" "Send all messages received on to \n" "If is omitted, then <can_interface> is used for sending\n" "\n" "Options:\n" " -f, --family=FAMILY Protocol family (default PF_CAN = %d)\n" " -t, --type=TYPE Socket type, see man 2 socket (default SOCK_RAW = %d)\n" " -p, --protocol=PROTO CAN protocol (default CAN_RAW = %d)\n" " -v, --verbose be verbose\n" " -h, --help this help\n" " --version print version information and exit\n", prg, PF_CAN, SOCK_RAW, CAN_RAW); } void sigterm(int signo) { running = 0; } int main(int argc, char **argv) { struct can_frame frame; struct ifreq ifr[2]; struct sockaddr_can addr[2]; char *intf_name[2]; int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW; int nbytes, i, out; int opt; int s[2]; int verbose = 0;
} 2.代码文件.h /* include/can_config.h. Generated from can_config.h.in by configure. */ /* include/can_config.h.in. Generated from configure.ac by autoheader. */ /* debugging */ /* #undef DEBUG */ /* Define to 1 if you have the <dlfcn.h> header file. */ #define HAVE_DLFCN_H 1 /* Define to 1 if you have the <fcntl.h> header file. */ #define HAVE_FCNTL_H 1 /* Define to 1 if you have the <inttypes.h> header file. */ #define HAVE_INTTYPES_H 1 /* Define to 1 if you have the <limits.h> header file. */ #define HAVE_LIMITS_H 1 /* Define to 1 if you have the <memory.h> header file. */ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the `socket' function. */ #define HAVE_SOCKET 1 /* Define to 1 if `stat' has the bug that it succeeds when given the zero-length file name argument. */ #define HAVE_STAT_EMPTY_STRING_BUG 1 /* Define to 1 if you have the <stdint.h> header file. */ #define HAVE_STDINT_H 1 /* Define to 1 if you have the <stdlib.h> header file. */ #define HAVE_STDLIB_H 1 /* Define to 1 if you have the `strchr' function. */ #define HAVE_STRCHR 1 /* Define to 1 if you have the <strings.h> header file. */ #define HAVE_STRINGS_H 1 /* Define to 1 if you have the <string.h> header file. */ #define HAVE_STRING_H 1 /* Define to 1 if you have the `strtoul' function. */ #define HAVE_STRTOUL 1 /* Define to 1 if you have the <sys/ioctl.h> header file. */ #define HAVE_SYS_IOCTL_H 1 /* Define to 1 if you have the <sys/socket.h> header file. */ #define HAVE_SYS_SOCKET_H 1 /* Define to 1 if you have the <sys/stat.h> header file. */ #define HAVE_SYS_STAT_H 1 /* Define to 1 if you have the <sys/types.h> header file. */ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the <unistd.h> header file. */ #define HAVE_UNISTD_H 1 /* Define to 1 if `lstat' dereferences a symlink specified with a trailing slash. */ #define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 /* Define as the return type of signal handlers ( #define RETSIGTYPE void /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Version number of package */ #define VERSION "1.0" /* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>, <pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the #define below would cause a syntax error. */ /* #undef _UINT32_T */ /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ /* Define to `unsigned int' if <sys/types.h> does not define. */ /* #undef size_t */ /* Define to `int' if <sys/types.h> does not define. */ /* #undef ssize_t */ /* Define to the type of an unsigned integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ /* #undef uint32_t */ 3.makefile文件 source /home/jack/omapl138/ti/mcsdk_1_01_00_02/linux-devkit/environment-setup#CC = gcc CFLAGS = -Wall -g INCLUDES = -I. LDFLAGS = VPATH = . OBJS = tl_can_echo.o TARGETS = tl_can_echo all : $(TARGETS) tl_can_echo: $(OBJS) %.o:%.c .PHONY: clean: rm -f $(TARGETS) *.o |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
【米尔-紫光MYB-J7A100T国产FPGA开发板试用】米尔-紫光PG2L100H国产FPGA开发板开箱评测
1017 浏览 0 评论
【米尔-紫光PG2L100H国产FPGA开发板试用】官方LED例程测试体验
4886 浏览 0 评论
【米尔-紫光PG2L100H国产FPGA开发板试用】上电测试报告
4532 浏览 0 评论
【米尔-紫光PG2L100H国产FPGA开发板试用】开箱评测!米尔电子PG2L100H开发板深度体验报告
985 浏览 0 评论
【米尔-Xilinx XC7A100T FPGA开发板试用】+04.SFP之Aurora测试(zmj)
814 浏览 0 评论
【米尔-瑞米派兼容树莓派扩展模块-试用体验】基于ROS系统的三麦轮小车自主导航
3653浏览 2评论
【米尔NXP i.MX 93开发板试用评测】5、安装Debian和排除启动故障
722浏览 2评论
【米尔NXP i.MX 93开发板试用评测】2、异构通信环境搭建和源码编译
863浏览 2评论
【米尔-瑞米派兼容树莓派扩展模块-试用体验】Free RTOS应用开发环境部署
1454浏览 1评论
【米尔-芯驰D9开发板- 国产平台试用】- 03- 外设接口测试-U盘、485总线
6816浏览 1评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 15:21 , Processed in 0.680424 second(s), Total 64, Slave 48 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号