优秀论文~CAN总线通信研究与软件设计毕业论文设计 下载本文

内容发布更新时间 : 2024/5/18 0:43:42星期一 下面是文章的全部内容请认真阅读。

北京邮电大学毕业设计

CAN总线通信研究与软件设计

摘 要

现场总线,又称现场网络,是一种工业数据通信总线。在当今时代,现场总线的发展速度非常之快,它的出现为工业的发展提供了非常好的技术保障,为分布式控制系统中的各个节点之间的数据通信提供了非常好的技术保障。CAN总线是一种半双工通信的串行通信网络,属于现场总线的一种,它的数据通信功能强大,能够有效的支持分布式控制或实时控制系统。相比与其它现场总线,CAN总线具有通信快、效率高、易实现、可靠性高等优势,现在已经在很多领域中都得到了应用。

本文主要研究CAN总线通信技术的原理及其技术特点,研究了CAN通信的具体流程,包括初始化流程以及发送接收数据流程。运用C语言编写相关单片机程序以及CAN的通信程序实现通信。

本次软件设计是在keil4开发环境下进行的,主要编写了串口程序,SPI接口程序以及CAN的初始化、发送和接收数据程序,并与相关硬件设计结合,实现两个CAN节点之间的相互的数据通信。

关键词:现场总线;CAN总线;软件设计;通信

i

北京邮电大学毕业设计

CAN bus communication research and software design

Abstract

Field bus, also called the network, is a kind of industrial data communication bus. In today's era, the development of field bus speed is very fast, it provides a very good technical support for the development of industry, for data communication between each node in distributed control system provides a very good technical support. CAN bus is a half-duplex communication serial communication network, belongs to a kind of fieldbus, it has powerful data communication function, CAN effectively support distributed control or real-time control system. Compared with other field bus, CAN bus communication is fast, high efficiency, easy realize and high reliability advantages, now has been applied in many fields.

In this paper, the principle of the CAN bus communication technology and its technical characteristics, research the CAN communication process, including the initialization process and the process to send and receive data. Using C language to write the microcontroller program, and CAN communication program to realize communication.

The software design is under the environment of keil4 development, mainly to write a serial program, SPI interface program and CAN the initialization, send and receive data, and combined with relevant hardware design, the two CAN achieve data communication between nodes.

Key words: The fieldbus;CAN bus; The software design;Communication;

ii

北京邮电大学毕业设计

目 录

摘 要 ................................................................... i Abstract ................................................................ ii 1 绪论 .................................................................. 1

1.1 课题背景 ......................................................... 1 1.2 选题目的 ......................................................... 1 1.3 选题意义 ......................................................... 1 1.4 本文结构 ......................................................... 2 2 相关技术介绍 .......................................................... 3

2.1 CAN总线介绍 ..................................................... 3

2.1.1 CAN总线技术简介 ............................................ 3 2.1.2 CAN总线的发展概况 .......................................... 4 2.1.3 CAN总线的特点 .............................................. 4 2.1.4 CAN总线协议介绍 ............................................ 5 2.2 单片机介绍 ....................................................... 6

2.2.1 单片机硬件特性 ............................................. 7 2.2.2 单片机发展状况 ............................................. 7 2.2.3 单片机设计 ................................................. 8 2.3 开发环境及开发语言介绍 .......................................... 10

2.3.1 keil uvision4开发环境简介 ................................. 10 2.3.2 开发语言介绍 .............................................. 11

3 系统设计 ............................................................. 13

3.1 设计目的 ........................................................ 13 3.2 设计原理及方案 .................................................. 13

3.2.1 CAN总线通信原理 ........................................... 13 3.2.2 软件设计方案 .............................................. 13 3.3 软件设计流程图 .................................................. 14

3.3.1 主程序流程图 .............................................. 14 3.3.2串口设计流程图 .............................................. 15 3.3.2 CAN初始化流程图 ........................................... 16 3.3.3 发送数据子程序流程图 ...................................... 18 3.3.4 接收数据子程序流程图 ...................................... 18

4 系统实现 ............................................................. 20

4.1 串口实现 ........................................................ 20 4.2 SPI接口实现 .................................................... 21 4.3 MCP2515初始化 .................................................. 24 4.4 CAN发送和接收数据实现 .......................................... 26 5 测试及设计成果分析 ................................................... 29

5.1 硬件连接 ........................................................ 29 5.2 下载程序到单片机 ................................................ 29 5.3 结果分析 ........................................................ 31 结 论 .................................................................. 34