使用STM32F103的CAN通信就是用这4个结构体函数,把他们理解透了,CAN就好用了

CAN的结构体定义在stm32f10x_can.h里面

/*********************************************************************************************************************************************************

//CAN初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint16_t CAN_Prescaler; /*!< Specifies the length of a time quantum. It ranges from 1 to 1024. */预分频器<指定时间量的长度。范围从1到1024>

uint8_t CAN_Mode; /*!< Specifies the CAN operating mode.This parameter can be a value of @ref CAN_operating_mode */指定CAN操作模式

/*************

有四种模式可选

相关宏

#define CAN_Mode_Normal ((uint8_t)0x00) /*!< normal mode */正常模式
#define CAN_Mode_LoopBack ((uint8_t)0x01) /*!< loopback mode */回环模式
#define CAN_Mode_Silent ((uint8_t)0x02) /*!< silent mode */静音模式
#define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) /*!< loopback combined with silent mode */环回与静音模式相结合

****************/

uint8_t CAN_SJW; /*!< Specifies the maximum number of time quanta the CAN hardware is allowed to lengthen or shorten a bit to perform resynchronization.This parameter can be a value of @ref CAN_synchronisation_jump_width */

/**********************************

硬件同步,再同步

指定时间量的最大数量,允许CAN硬件加长或,缩短一点以执行重新同步。此参数的值可以是@参考CAN\U同步\U跳跃\U宽度*

重新同步跳跃宽度间单位

相关宏

#define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */1个tq
#define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */2个tq
#define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */3个tq
#define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */4个tq

***********************************************/

uint8_t CAN_BS1; /*!< Specifies the number of time quanta in Bit Segment 1. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */指定时间量(以位为单位)

/*****************************************************

硬件同步,再同步

设置采样点时间段第一段

相关宏

#define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */
#define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */
#define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */
#define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */
#define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */
#define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
#define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
#define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
#define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
#define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
#define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
#define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */

********************************************************/

uint8_t CAN_BS2; /*!< Specifies the number of time quanta in Bit Segment 2.his parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */指定时间量(以位为单位)

/*****************************************************

硬件同步,再同步

设置采样点时间段第二段

相关宏

#define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
#define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
#define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
#define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
#define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
#define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
#define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
#define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */

********************************************************/

unctionalState CAN_TTCM; /*!< Enable or disable the time triggered communication mode. This parameter can be set either to ENABLE or DISABLE.

/************************************************************************

!<启用或禁用时间触发模式。可以设置此参数启用或禁用。*/

ENABLE or DISABLE

*************************************************************************/

FunctionalState CAN_ABOM; /*!< Enable or disable the automatic bus-off management. This parameter can be set either to ENABLE or DISABLE. */

/***********************************************************************

启用或禁用自动离线管理。此参数可以设置为启用或禁用。*

ENABLE or DISABLE

************************************************************************/

FunctionalState CAN_AWUM; /*!< Enable or disable the automatic wake-up mode. This parameter can be set either to ENABLE or DISABLE. */

/***********************************************************************

<启用或禁用自动唤醒模式。此参数可以设置为启用或禁用。*/

ENABLE or DISABLE

**************************************************************************/

FunctionalState CAN_NART; /*!< Enable or disable the no-automatic retransmission mode. This parameter can be set either to ENABLE or DISABLE. */

/*******************************************************************************

<启用或禁用no自动

重传模式。此参数可以是

设置为启用或禁用。*/

ENABLE or DISABLE

********************************************************************************/

FunctionalState CAN_RFLM; /*!< Enable or disable the Receive FIFO Locked mode.This parameter can be set either to ENABLE or DISABLE. */

/*******************************************************************************

<启用或禁用接收FIFO锁定模式。此参数可以设置为启用或禁用。*/

ENABLE or DISABLE

********************************************************************************/

FunctionalState CAN_TXFP; /*!< Enable or disable the transmit FIFO priority.his parameter can be set either to ENABLE or DISABLE. */

/*******************************************************************************

<启用或禁用传输FIFO优先级。此参数可以设置为启用或禁用。*/

ENABLE or DISABLE

********************************************************************************/

} CAN_InitTypeDe

/*********************************************************************************************************************************************************

过滤设置 初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint16_t CAN_FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bitconfiguration, first one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的过滤器标识符的高16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bitconfiguration, second one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的 过滤器标识符的低16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,according to the mode (MSBs for a 32-bit configuration,first one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的 过滤器屏蔽标识符的高16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,according to the mode (LSBs for a 32-bit configuration,second one for a 16-bit configuration).This parameter can be a value between 0x0000 and 0xFFFF */

/*******************************************************************************

/*!<指定32位的  过滤器屏蔽标识符的低16位值,此参数可以是介于0x0000和0xFFFF之间的值*/

********************************************************************************/

uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.This parameter can be a value of @ref CAN_filter_FIFO */

/******************************************************************************* 

指定将分配给过滤器的FIFO(0或1)。此参数可以是@ref can_filter_FIFO的值*/

#define CAN_Filter_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */
#define CAN_Filter_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */

********************************************************************************/

uint8_t CAN_FilterNumber; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */

/*******************************************************************************

指定要初始化的过滤器。范围从0到13

********************************************************************************/

uint8_t CAN_FilterMode; /*!< Specifies the filter mode to be initialized.This parameter can be a value of @ref CAN_filter_mode */

/*******************************************************************************

指定要初始化的过滤器模式

相关宏

#define CAN_FilterMode_IdMask ((uint8_t)0x00) /*!< identifier/mask mode */标识符/   掩码模式
#define CAN_FilterMode_IdList ((uint8_t)0x01) /*!< identifier list mode */标识符  列表模式

********************************************************************************/

uint8_t CAN_FilterScale; /*!< Specifies the filter scale.This parameter can be a value of @ref CAN_filter_scale */

/*******************************************************************************

指定过滤器过滤器位宽。

#define CAN_FilterScale_16bit ((uint8_t)0x00) /*!< Two 16-bit filters */
#define CAN_FilterScale_32bit ((uint8_t)0x01) /*!< One 32-bit filter */

********************************************************************************/

FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter.This parameter can be set either to ENABLE or DISABLE. */

/******************************************************************************* 

<启用或禁用过滤器。此参数可以设置为启用或禁用。

ENABLE or DISABLE

********************************************************************************/

} CAN_FilterInitTypeDef;

/*********************************************************************************************************************************************************

CAN发送消息初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint32_t StdId; /*!< Specifies the standard identifier.This parameter can be a value between 0 to 0x7FF. */

/******************************************************************************* 

/*!<指定标准标识符。此参数可以是0到0x7FF之间的值。*/

********************************************************************************/

uint32_t ExtId; /*!< Specifies the extended identifier.This parameter can be a value between 0 to 0x1FFFFFFF. */

/******************************************************************************* 

!<指定扩展标识符。此参数可以是0到0x1FFFFFF之间的值。*/

********************************************************************************/

uint8_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of @ref CAN_identifier_type */

/******************************************************************************* 

指定消息的标识符类型将被发送

#define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */标准Id
#define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */扩展Id

********************************************************************************/

uint8_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. This parameter can be a value of @ref CAN_remote_transmission_request */

/******************************************************************************* 

指定将要传输的消息的帧类型

#define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame */数据帧
#define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */远程帧

********************************************************************************/

uint8_t DLC; /*!< Specifies the length of the frame that will be transmitted. This parameter can be a value between 0 to 8 */

/******************************************************************************* 

!<指定将要传输的帧的长度。此参数可以是介于0到8*/

********************************************************************************/

uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0 to 0xFF. */

/******************************************************************************* 

<包含要传输的数据。范围从0到0xFF。*/

将要发送的数据存放到这个数组里面

for(i = 0;i < 8;i++)
{
TxMessage.Data[i] = *(ptr + i);
}

********************************************************************************/

} CanTxMsg;

/*********************************************************************************************************************************************************

CAN接收消息初始化结构定义

*************************************************************************************************************************************************************/

typedef struct
{
uint32_t StdId; /*!< Specifies the standard identifier.This parameter can be a value between 0 to 0x7FF. */

/******************************************************************************* 

<指定标准标识符。此参数可以是0到0x7FF之间的值。*/

********************************************************************************/

uint32_t ExtId; /*!< Specifies the extended identifier.This parameter can be a value between 0 to 0x1FFFFFFF. */

/******************************************************************************* 

*!<指定扩展标识符。此参数可以是0到0x1FFFFFF之间的值。*/

********************************************************************************/

uint8_t IDE; /*!< Specifies the type of identifier for the message that will be received. This parameter can be a value of @ref CAN_identifier_type */

/******************************************************************************* 

/*!<指定将接收的消息的标识符类型。此参数可以是@ref can\u identifier\u type的值*/

#define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */标准Id
#define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */扩展Id

********************************************************************************/

uint8_t RTR; /*!< Specifies the type of frame for the received message.This parameter can be a value of @ref CAN_remote_transmission_request */

/******************************************************************************* 

<指定接收消息的帧类型。此参数可以是@ref can\u remote\u transmission\u request的值*/

#define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame *//数据帧
#define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */远程帧

********************************************************************************/

uint8_t DLC; /*!< Specifies the length of the frame that will be received.This parameter can be a value between 0 to 8 */

/******************************************************************************* 

<指定将接收的帧的长度。此参数可以是0到8之间的值*/

********************************************************************************/

uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to 0xFF. */

/******************************************************************************* 

<包含要接收的数据。范围从0到0xFF。*/

接收到的数据存放在这个数组里面

********************************************************************************/

uint8_t FMI; /*!< Specifies the index of the filter the message stored in the mailbox passes through. This parameter can be a value between 0 to 0xFF */

/******************************************************************************* 

指定邮箱中存储的邮件通过的筛选器的索引。此参数可以是0到0xFF之间的值*/

********************************************************************************/

} CanRxMsg;

STM32F103的CAN结构体学习的更多相关文章

  1. FFmpeg 结构体学习(二): AVStream 分析

    在上文FFmpeg 结构体学习(一): AVFormatContext 分析我们学习了AVFormatContext结构体的相关内容.本文,我们将讲述一下AVStream. AVStream是存储每一 ...

  2. FFmpeg 结构体学习(三): AVPacket 分析

    在上文FFmpeg 结构体学习(二): AVStream 分析我们学习了AVStream结构体的相关内容.本文,我们将讲述一下AVPacket. AVPacket是存储压缩编码数据相关信息的结构体.下 ...

  3. FFmpeg 结构体学习(四): AVFrame 分析

    在上文FFmpeg 结构体学习(三): AVPacket 分析我们学习了AVPacket结构体的相关内容.本文,我们将讲述一下AVFrame. AVFrame是包含码流参数较多的结构体.下面我们来分析 ...

  4. FFmpeg 结构体学习(五): AVCodec 分析

    在上文FFmpeg 结构体学习(四): AVFrame 分析我们学习了AVFrame结构体的相关内容.本文,我们将讲述一下AVCodec. AVCodec是存储编解码器信息的结构体.下面我们来分析一下 ...

  5. FFmpeg 结构体学习(六): AVCodecContext 分析

    在上文FFmpeg 结构体学习(五): AVCodec 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVCodecContext. AVCodecContext是包含变量较多的结 ...

  6. FFmpeg 结构体学习(七): AVIOContext 分析

    在上文FFmpeg 结构体学习(六): AVCodecContext 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVIOContext. AVIOContext是FFMPEG管 ...

  7. FFmpeg 结构体学习(一): AVFormatContext 分析

    在 FFmpeg 学习(六):FFmpeg 核心模块 libavformat 与 libavcodec 分析 中,我们分析了FFmpeg中最重要的两个模块以及重要的结构体之间的关系. 后面的文章,我们 ...

  8. C语言 结构体学习

    结构体的学习 struct 结构是由基本数据类型构成的.并用一个标识符来命名的各种变量的组合. 结构中可以使用不同的数据类型. 结构说明和结构变量定义 在Turbo C中, 结构也是一种数据类型,可以 ...

  9. Linux C语言结构体-学习笔记

    Linux C语言结构体简介 前面学习了c语言的基本语法特性,本节进行更深入的学习. 预处理程序. 编译指令: 预处理, 宏定义, 建立自己的数据类型:结构体,联合体,动态数据结构 c语言表达式工具 ...

随机推荐

  1. 蓝桥杯——剪邮票(2016JavaB组第10题)

    剪邮票(16JavaB10) 如[图1], 有12张连在一起的12生肖的邮票. 现在你要从中剪下5张来,要求必须是连着的. (仅仅连接一个角不算相连) 比如,[图2],[图3]中,粉红色所示部分就是合 ...

  2. C++分支结构,求一元二次方程的根

    总时间限制:  1000ms 内存限制:  65536kB 描述 利用公式x1 = (-b + sqrt(b*b-4*a*c))/(2*a), x2 = (-b - sqrt(b*b-4*a*c))/ ...

  3. fastjson JSONObject简单使用

    工作中用的蛮多的最近整理下,概括地说 通过这个工具可以让一个json在json串,JSONObject,java对象之间进行转化 首先我们先写2个bean来构成一个比较复杂的json串: public ...

  4. 一个神奇的bug:OOM?优雅终止线程?系统内存占用较高?

    摘要:该项目是DAYU平台的数据开发(DLF),数据开发中一个重要的功能就是ETL(数据清洗).ETL由源端到目的端,中间的业务逻辑一般由用户自己编写的SQL模板实现,velocity是其中涉及的一种 ...

  5. Steps 组件的设计与实现

    NutUI 组件源码揭秘 前言 本文的主题是 Steps 组件的设计与实现.Steps 组件是 Steps 步骤和 Timeline 组件结合的组件,在此之前他们是两个不同的组件,在 NutUI 最近 ...

  6. Docker 入门介绍

    Docker是什么 从发布到现在 docker一直很受关注,在一定程度是改变了软件行业 如果你还不知道 docker 是什么是不是有点out了,接下来我们来介绍docker是什么,解决了什么问题,好处 ...

  7. kafka监听出现的问题,解决和剖析

    问题如下: kafka为什么监听不到数据 kafka为什么会有重复数据发送 kafka数据重复如何解决 为什么kafka会出现俩个消费端都可以消费问题 kafka监听配置文件 一. 解决问题一(kaf ...

  8. 基于 MongoDB 动态字段设计的探索 (二) 聚合操作

    业务需求及设计见前文:基于 MongoDB 动态字段设计的探索 根据专业计算各科平均分 (总分.最高分.最低分) public Object avg(String major){ Aggregatio ...

  9. 强大的拉姆表达式转Sql 类库 - SqlSugar 隐藏功能之Lambda

    使用场景 1.Lambda to sql 一直是ORM中最难的功能之一,如果有现成的解析库那么自已写一个ORM难度将大大降低 2.通过Lambda作为KEY进行缓存操作,特别是仓储模式想要拿到表达式进 ...

  10. 转:Python常见字符编码及其之间的转换

    参考:Python常见字符编码 + Python常见字符编码间的转换 一.Python常见字符编码 字符编码的常用种类介绍 第一种:ASCII码 ASCII(American Standard Cod ...