使用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. Codeforces Round #674 (Div. 3) F. Number of Subsequences 题解(dp)

    题目链接 题目大意 给你一个长为d只包含字符'a','b','c','?' 的字符串,?可以变成a,b,c字符,假如有x个?字符,那么有\(3^x\)个字符串,求所有字符串种子序列包含多少个abc子序 ...

  2. 【python】Matplotlib作图中有多个Y轴

    在作图过程中,需要绘制多个变量,但是每个变量的数量级不同,在一个坐标轴下作图导致曲线变化很难观察,这时就用到多个坐标轴.本文除了涉及多个坐标轴还包括Axisartist相关作图指令.做图中label为 ...

  3. 2、Spring Cloud和dubbo简介

    1.Spring Cloud简介 (1).Spring Cloud简介 SpringCloud,基于SpringBoot提供了一套微服务解决方案,包括服务注册与发现,配置中心,全链路监控,服务网关,负 ...

  4. Integer中的奇妙位运算

    Integer中的奇妙位运算 参考资料 https://segmentfault.com/a/1190000015763941 highestOneBit(int i) 函数的作用是获得传入参数的最高 ...

  5. ElementUI el-date-picker 限制选中日期前后30天,大于当天不可选

    <template> <el-date-picker v-model="date" type="daterange" range-separa ...

  6. PyQt(Python+Qt)学习随笔:QDateEdit日期编辑部件和QTimeEdit时间编辑部件

    专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 Designer输入部件中,Date Edit和T ...

  7. 老猿学5G随笔:5G网元功能体NF以及NF之间的两种接口--服务化接口和参考点

    一.5G功能体之间的接口类型 5G不同功能体之间提供了两种接口: 服务化接口:Service-basedinterface,这个是类似微服务化架构的服务注册和服务发现来实现的功能体对外暴露的接口,这种 ...

  8. Python正则表达式书写容易碰到的陷阱:\W*和\W*?匹配过程遇到的问题

    老猿在分析<Python正则表达式\W+和\W*匹配过程的深入分析>中的问题时,想到一个问题,如果"re.split('(\W*)','Hello,world')"的处 ...

  9. Mysql 存储过程(变量、定义条件、处理程序、光标、流程控制构造)

    最近由于有同事编写了存储函数,需要进行验证,但是对存储过程一直不是很了解,所以抽时间了解了一下存储过程的基本语法.本篇文章主要包括介绍了存储过程的5个小语法:declare语句的变量.定义条件.处理程 ...

  10. mysqldump: [ERROR] unknown variable 'database=test'.

    背景: 导出数据库test库的test表数据出现报错信息:mysqldump: [ERROR] unknown variable 'database=test'. 原来是my.cnf参数文件配置了以下 ...