STM32F103的CAN结构体学习
使用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结构体学习的更多相关文章
- FFmpeg 结构体学习(二): AVStream 分析
在上文FFmpeg 结构体学习(一): AVFormatContext 分析我们学习了AVFormatContext结构体的相关内容.本文,我们将讲述一下AVStream. AVStream是存储每一 ...
- FFmpeg 结构体学习(三): AVPacket 分析
在上文FFmpeg 结构体学习(二): AVStream 分析我们学习了AVStream结构体的相关内容.本文,我们将讲述一下AVPacket. AVPacket是存储压缩编码数据相关信息的结构体.下 ...
- FFmpeg 结构体学习(四): AVFrame 分析
在上文FFmpeg 结构体学习(三): AVPacket 分析我们学习了AVPacket结构体的相关内容.本文,我们将讲述一下AVFrame. AVFrame是包含码流参数较多的结构体.下面我们来分析 ...
- FFmpeg 结构体学习(五): AVCodec 分析
在上文FFmpeg 结构体学习(四): AVFrame 分析我们学习了AVFrame结构体的相关内容.本文,我们将讲述一下AVCodec. AVCodec是存储编解码器信息的结构体.下面我们来分析一下 ...
- FFmpeg 结构体学习(六): AVCodecContext 分析
在上文FFmpeg 结构体学习(五): AVCodec 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVCodecContext. AVCodecContext是包含变量较多的结 ...
- FFmpeg 结构体学习(七): AVIOContext 分析
在上文FFmpeg 结构体学习(六): AVCodecContext 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVIOContext. AVIOContext是FFMPEG管 ...
- FFmpeg 结构体学习(一): AVFormatContext 分析
在 FFmpeg 学习(六):FFmpeg 核心模块 libavformat 与 libavcodec 分析 中,我们分析了FFmpeg中最重要的两个模块以及重要的结构体之间的关系. 后面的文章,我们 ...
- C语言 结构体学习
结构体的学习 struct 结构是由基本数据类型构成的.并用一个标识符来命名的各种变量的组合. 结构中可以使用不同的数据类型. 结构说明和结构变量定义 在Turbo C中, 结构也是一种数据类型,可以 ...
- Linux C语言结构体-学习笔记
Linux C语言结构体简介 前面学习了c语言的基本语法特性,本节进行更深入的学习. 预处理程序. 编译指令: 预处理, 宏定义, 建立自己的数据类型:结构体,联合体,动态数据结构 c语言表达式工具 ...
随机推荐
- Eclipse改字体大小
Windows ->Perferences ->General ->Appearance ->Colors and Fonts ->Basic ->Text Fon ...
- [题解] 洛谷 P3393 逃离僵尸岛
题目TP门 很明显是一个最短路,但是如何建图才是关键. 对于每一个不可遍历到的点,可以向外扩散,找到危险城市. 若是对于每一个这样的城市进行搜索,时间复杂度就为\(O(n^2)\),显然过不了.不妨把 ...
- Python中排序函数sorted和排序方法sort的异同点对比分析
Python中对序列进行排序有两种方法,一种是使用python内置的全局sorted函数,另一种是使用序列内置的sort方法. 一. 两者相同点 在支持sort方法的序列中都可以对序列进行排序: 二者 ...
- PyQt(Python+Qt)学习随笔:Qt Designer中部件的locale属性
locale属性用于设置语言环境,包括语言和国家.如果一个部件没有设置语言环境,则使用父对象的语言环境或者默认语言环境(如果这个部件是顶层部件). 可以使用locale()获取部件的语言环境,也可以通 ...
- PyQt(Python+Qt)学习随笔:使用QtWidgets.qApp实现在程序中随时访问应用的方法
在PyQt应用中,任何一个应用在启动时必须创建一个基于QtWidgets.QApplication或其派生类对应的应用对象,该对象用于处理事件. 如果需要在应用代码中的任何位置都能访问该应用对象,可以 ...
- RedHat操作指令第2篇
六.RPM包管理命令 主要功能 查询RPM软件.包文件的相关信息 安装.升级.卸载RPM软件包 维护RPM数据库信息 查询RPM软件信息 查询已安装的RPM软件信息 格式:rpm -q[子选项] [软 ...
- CobaltStrike 生成office宏病毒进行钓鱼攻击
关于WORD宏: 在百度百科上有: 宏是一个批量处理程序命令,正确地运用它可以提高工作效率.微软的office软件允许用户自己编写,叫VBA的脚本来增加其灵活性,进一步扩充它的能力.如完打开word文 ...
- pandas LabelEncoder 测试集出现了训练集中未出现过的值怎么解决(y contains previously unseen labels 解决方法)
for i in categorical_ix: le = joblib.load(f"./LabelEncoder/{i}_LabelEncoder.model") #由于tes ...
- Symbol类型是不可枚举的
const info = { [Symbol('a')]: 'b' } console.log(info)//{Symbol('a'): 'b'} console.log(Object.keys(in ...
- ThreadLocal原理记录,别被坑了!!
简介 ThreadLocal的用处 ThreadLocal是为了将数据记录一份到某个线程里,确保该数据线程安全 例如数据库的Connection放入ThreadLocal,一个事务会用到很多DAO,但 ...